Answer the question
In order to leave comments, you need to log in
How to fill checkboxes regarding get-parameters in the address bar in Laravel?
I am developing an online store on Laravel. I am currently working on the implementation of the product filter.
It is necessary, having a string with search parameters, to fill in the checkboxes in the form that performs filtering.
Those. now I have this line:
localhost:3000/?category=tops&color=black
And I want the checkboxes to be filled like this on page load:
<form action="{{ route('layouts.main') }}" method="GET">
<h4>Категория</h4>
<label>
<input type="checkbox" checked="" name="category[]" value="tops">
Топы
</label>
<label>
<input type="checkbox" name="category[]" value="bottoms">
Нижнее бельё
</label>
<h4>Цвет</h4>
<label>
<input type="checkbox" checked="" name="category[]" value="black">
Чёрный
</label>
<label>
<input type="checkbox" name="category[]" value="white">
Белый
</label>
</form>
if($request->category){
$categories = $request->category;
}
if($request->color){
$colors = $request->color;
}
return view('layouts.main')->with([
'categories' => $categories,
'colors' => $colors
]);
Answer the question
In order to leave comments, you need to log in
For example like this
Better yet, use the extension for forms, then it will set the desired value itself if it comes with a request
https://laravelcollective.com/docs/5.4/html#checkb...Form::checkbox('name', 'value', true);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question