鉴于我的模型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 关注
- 93 浏览
添加回答
举报
0/150
提交
取消