Php 如何在Laravel项目中使用“按搜索获取参数”复选框填写搜索表单?

Php 如何在Laravel项目中使用“按搜索获取参数”复选框填写搜索表单?,php,laravel,Php,Laravel,我使用Laravel在电子商务网站上过滤产品 I have this url localhost:3000/?category=tops&color=black 我需要在我的筛选搜索表单中通过“选中”来填写复选框,如下所示: <form action="{{ route('layouts.main') }}" method="GET"> <h4>Category</h4> <label> <input type="chec

我使用Laravel在电子商务网站上过滤产品

I have this url localhost:3000/?category=tops&color=black
我需要在我的筛选搜索表单中通过“选中”来填写复选框,如下所示:

<form action="{{ route('layouts.main') }}" method="GET">

<h4>Category</h4>
<label>
    <input type="checkbox" checked="" name="category[]" value="tops">
    Tops
</label>
<label>
    <input type="checkbox" name="category[]" value="bottoms">
    Bottoms
</label>

<h4>Color</h4>
<label>
    <input type="checkbox" checked="" name="category[]" value="black">
    Black
</label>
<label>
    <input type="checkbox" name="category[]" value="white">
    White
</label>

</form>

类别
最上等的
屁股
颜色
黑色
白色

我如何才能做到这一点?

将所有类别放在数组或集合中(例如
Category::all()
),并以这种方式进行处理

@foreach($categories as $category)
   <label>
     <input {{ in_array(strtolower($category->name), Request::get('categories')) ? 
     'checked="checked"':
     '' }} 
     type="checkbox" name="category[]" value="{{ strtolower($category->name) }}">
     {{ $category->name }}
   </label>
@endforeach
@foreach($categories作为$category)
名称),请求::获取('categories')?
“checked=”checked“:
'' }} 
type=“checkbox”name=“category[]”value=“{{{strtolower($category->name)}}>
{{$category->name}
@endforeach