I have a problem updating a field in my User Model.
I have a field for activating a public_profile defined as boolean:
...
$table->boolean('public_profile')->default(false);
...
in the Model itself i define.
protected $fillable = [..., 'public_profile', ...];
Now i try to update the field via axios depending on the status of an checkbox.
$('#change_public_profile').change(function () {
message={
_token: $('meta[name="csrf-token"]').attr('content'),
public_profile: $('#change_public_profile').is(':checked')
}
axios.post('SOME URL', message).....
Now in my controller i read the request:
$public_profile = $request->input('public_profile');
And call the function:
Auth::user()->togglePublicProfile($public_profile);
In the User Model I have the function:
public function togglePublicProfile($toggleTo){
$user = $this;
$user->public_profile = $toggleTo;
return $user->save();
}
I also tried with boolval() as Mutator, but it never changed. I do the same to chagne a string value, and there it works well.
Where is my mistake?