I am beginner in larval and I want to edit and update checkbox values. Now I can able to store checkbox values, but when I click edit it's not showing checked values in edit view. So please help me how can I resolve this solution. Here I will give you my code.
My Blade File
<input type="checkbox" name="hobbies" id="readbooks" value="Readbooks" {{ $users->hobbies=="Readbooks"? 'checked':'' }}>Readbooks
<input type="checkbox" name="hobbies" id="music" value="Music"{{ $users->hobbies=="Music"? 'checked':'' }}/> Music
<input type="checkbox" name="hobbies" id="games" value="Games" {{ $users->hobbies=="Games"? 'checked':'' }}/> Games
My controller File
public function edit($id)
{
$users = User::find($id);
echo $users;
return view('edit',['users'=>$users]);
}
public function updateUser(Request $request, $id)
{
User::whereId($id)->update($validatedData);
return redirect("view")->withSuccess('User! Successfully Updated!');
}
$users->hobbiesis an array if I am not wrong and you're simply comparing with a single string word which is failing the condition. You should usein_array("Music", $users->hobbies)instead ofusers->hobbies=="Music"and so on.str_contains($users->hobbies, 'Music'). But only Karthika knows what it is ..!? ;-)