到目前为止,我知道我需要将复选框值存储在数组中,如下所示:
<input name="thinking_traps[]" type="checkbox" value="1">
<input name="thinking_traps[]" type="checkbox" value="2">
<input name="thinking_traps[]" type="checkbox" value="3">
但是我不确定如何将这些值正确传递给控制器并将其添加到迁移表中?是否将每个值作为单独的列添加到数据库中?
在这里,我尝试添加它们,就像任何其他输入一样:
public function store(Request $request)
{
$this->validate($request, [
'thought_entry' => 'required'
]);
$entry = new ThoughtJournal;
$entry->user_id = auth()->user()->id;
$entry['entry_date'] = date('Y-m-d H:i');
$entry->thought_entry = $request->input('thought_entry');
$entry->emotions = $request->input('emotions');
$entry->thinking_traps = $request->input('thinking_traps');
$entry->balanced_thought = $request->input('balanced_thought')
$entry->save();
return redirect('/dashboard');
}
public function up()
{
Schema::create('thoughtjournal', function (Blueprint $table) {
$table->increments('entry_id');
$table->integer('user_id');
$table->date('entry_date');
$table->mediumText('thought_entry');
$table->
$table->timestamps();
});
}
慕莱坞森
慕的地10843
Qyouu