我有這個問題,當我從表單輸入返回所有值時,它都返回填充的值。但是,當我在控制器中的存儲方法下持久存儲數據庫時,它會插入空值。誰可以幫我這個事?謝謝。以下是我的代碼。無法在laravel 5.1中插入值到數據庫中
public function store(EnrollmentRequest $request)
{
return $request->all();
return redirect('/enrollment/create');
}
正如您在頂部看到的那樣,它會返回所有輸入。但是,當我堅持它在數據庫上時,它只返回id和時間戳;
public function store(EnrollmentRequest $request)
{
$enrollment = Enrollment::create([$request->all()]);
return $enrollment; return redirect('/enrollment/create');
}
而且,這裏是我的報名表:
Schema::create('enrollments', function (Blueprint $table) {
$table->increments('id');
$table->integer('student_id');
$table->string('subject_description');
$table->string('subject_code');
$table->time('schedule');
$table->string('room_no');
$table->integer('no_of_units');
$table->string('section');
$table->timestamps();
});
也是我的主題表:
Schema::create('subjects', function (Blueprint $table) {
$table->increments('id');
$table->string('subject_code');
$table->string('subject_description');
$table->time('schedule');
$table->string('room_no');
$table->integer('no_of_units');
$table->timestamps();
});
您的幫助是十分讚賞。
protected $table = 'enrollments';
protected $fillable = [
'subject_code',
'subject_description',
'section',
'schedule',
'room_no',
'no_of_units'
];
,你能否告訴我們該表的模式? – James
你可以試試$ enrollment = Enrollment :: create($ request-> all()); – Minhajul
在所有字段或任何特定字段上插入空值? –