今までデータ登録するときに以下のような形でやっていましたが、createで複数代入で登録しようとするとエラーがでてしまいます。
$test = new Model() $test->name = 'test'; $test->save();
問題の部分ですがすごくシンプルです。
/** * トップページのレンダリング。 * * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function top() { $test =JobFeature::create(['feature_name' => 'テスト']); // これはいける。 // $jobFeature = new JobFeature(); // $jobFeature->fill(['feature_name' => 'テスト']); // $jobFeature->save(); return view('template.publish.top'); }
テーブルもidはautoincrimentなのと日付も自動挿入なのでfeature_name
だけ指定すればいけるはずなんですが、
以下のエラーがでてしまいます。
SQLSTATE[HY000]: General error: 1364 Field 'feature_name' doesn't have a default value (SQL: insert into `job_features` (`updated_at`, `created_at`) values (2018-11-08 02:00:36, 2018-11-08 02:00:36))
create()メソッドでの登録だけができません。
ちなみにprotected $guarded = ['id'];
は指定していますので、id以外は書き換え可能ということになっているはずです。
回答1件
あなたの回答
tips
プレビュー