So far, I know I need to store the checkbox values in an array like so:
<input name="thinking_traps[]" type="checkbox" value="1">
<input name="thinking_traps[]" type="checkbox" value="2">
<input name="thinking_traps[]" type="checkbox" value="3">
But I'm not sure how to correctly pass these values to the controller and add them to the migration table? Will each value be added as a separate column in the database?
Here I've tried adding adding them like any other input:
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();
});
}
thinking_trapsarray could be 0,1,2 or 3 occurances. You are not even treating it like an array yet