I need to store checkbox values into the database. I have tried so many examples, but still am not able to do that, Here I will give you my code and give me the solution for this.
My Blade File
<div class="form-group row">
<label for="hobbies" class="col-md-4 col-form-label text-md-right">Hobbies</label>
<div class="col-md-6">
<input type="checkbox" name="hobbies[]" value="Readbooks"/> Readbooks
<input type="checkbox" name="hobbies[]" value="Games"/> Games
<input type="checkbox" name="hobbies[]" value="Music"/> Music
@if ($errors->has('hobbies'))
<span class="text-danger">{{ $errors->first('hobbies') }}</span>
@endif
</div>
</div>
My Controller File
public function postRegistration(Request $request)
{
$data = $request->all();
$check = $this->create($data);
return redirect("login")->withSuccess('Great! please login.');
}
public function create(array $data)
{
return User::create([
'hobbies' => $data->implode([',', (array) $data->get('hobbies')]),
]);
}
Error:Call to a member function implode() on array