I have simple form:
<form action="some_action" method="post">
<input type="checkbox" name="data[]" value="Data 1"/>
<input type="checkbox" name="data[]" value="Data 2"/>
<input type="checkbox" name="data[]" value="Data 3"/>
<button type="submit">Submit</button>
</form>
Values stores in array,
$data = new data();
$data->checkboxes = json_encode($request->all());
$data->save();
like
0 => "Data 1",
1 => "Data 2",
2 => "Data 3"
Now, i need to retrieve checkbox state. I passed into view decoded json:
$storedCheckboxes = json_decode($data->checkboxes);
return view('some.view')->with('storedCheckboxes', $storedCheckboxes);
And try to get it in blade:
<input name="data[]" type="checkbox" />
But i think it's wrong way, because in blade i should hardcode array position. And it works, but only if position present. Some help?
Aucun commentaire:
Enregistrer un commentaire