鑒于我的模型Person和Student. 現在,我的一個控制器正在這樣做:$person_id = \App\Models\Person::insertGetId(['name' => $request->name, ...]);\App\Models\Student::create(['person_id' => $person_id, ...]);$student = \App\Models\Student::where('person_id', $person_id)->first();dd($student);在執行期間,一切都已保存,但我的問題是為什么我在死亡和轉儲時收到空值?順便說一下,我的student表primary和foreign鍵是person_id列。編輯class Student extends Model{ protected $fillable = ['section', 'current_year'];//there are other attribute here which I didn't show because I am using mobile public function person(){ return $this->belongsTo('App\Models\Person', 'person_id', 'id'); } ...}
1 回答

HUH函數
TA貢獻1836條經驗 獲得超4個贊
添加person_id
屬性$fillable
:
protected $fillable = ['section', 'current_year', 'person_id'];
- 1 回答
- 0 關注
- 113 瀏覽
添加回答
舉報
0/150
提交
取消