Why does the following hard coded eloquent query work:
Auth::user()->update(['text_only_email' => true ]);
But when the data comes via a form checkbox input it always updates as false even when the input is true ?
$data['text_only_email'] = $request->input('text_only_email', false);
Auth::user()->update($data);
See results from die and dump to prove the incoming value is true:
$data['text_only_email'] = $request->input('text_only_email', false);
dd($data);
Results of dump:
array:1 [▼
"text_only_email" => "true"
]
* UPDATE *
I've added the following mutator to my User model to cast as boolean but it still doesnt work. Is my casting a string to boolean correct?
public function setTextOnlyEmailAttribute($value)
{
$this->attributes['text_only_email'] = (bool)($value);
}