我有两个具有关系的表,但是当我将数据发送到数据库中时,我得到了NULL
,我通常在laravel中将Laravel与Vuejs一起使用,我可以使用foreach循环来这样做,但是我是laravel&的初学者Vuejs
我的两个表是学生和父母,我在学生表上有一个引用父母ID的外键
任何可以帮助我解决这个问题的人
我的问题是,当我发送数据时,将学生表中的外键插入为NULL
这是我的学生模型:
protected $fillable = [
'pregistration_id',
'admission_no',
'fname',
'mname',
'lname',
'dob',
'gender',
'primary_school',
'form_enrolled',
'transfered_from',
'transfered_to',
];
这是我的父模型:
protected $fillable = [
'fname',
'mname',
'lname',
'residence',
'phone',
'occupation',
];
这是我的学生负责人:
return Student::create([
'pregistration_id'=>$request['pregistration_id'],
'admission_no'=>$request['admission_no'],
'fname'=>$request['fname'],
'mname'=>$request['mname'],
'lname'=>$request['lname'],
'dob'=>$request['dob'],
'gender'=>$request['gender'],
'primary_school'=>$request['primary_school'],
'form_enrolled'=>$request['form_enrolled'],
'transfered_from'=>$request['transfered_from'],
'transfered_to'=>$request['transfered_to'],
// dd($request->all())
]);
这是我的学生表:
Schema::create('students', function (Blueprint $table) {
$table->bigIncrements('id');
$table->bigInteger('pregistration_id')->unsigned()->nullable();
$table->integer('admission_no')->unique();
$table->string('fname');
$table->string('mname');
$table->string('lname');
$table->date('dob');
$table->string('gender');
$table->string('primary_school');
$table->string('form_enrolled');
$table->string('transfered_from');
$table->string('transfered_to');
$table->foreign('pregistration_id')->references('id')->on('pregistrations');
$table->timestamps();
});
这是Vue中学生部分的一部分:
data() {
return {
editmode: false,
students: {},
form: new Form({
id: '',
admission_no: '',
fname: '',
mname: '',
lname: '',
dob: '',
gender: '',
primary_school: '',
form_enrolled: '',
trasfered_from:'',
trasfered_to: ''
})
}
},