当前位置: 动力学知识库 > 问答 > 编程问答 >

Filter search in Laravel 5.2

问题描述:

I am creating a Search Filter in a project using Laravel 5.2. I tried for 2/3 days but cannot figure out how the query structure should be. Here is the Blade for filter

<form class="resume_filters in_sidebar" action="{{ action('[email protected]') }}" method="get">

<!-- Location -->

<div class="widget">

<h4>Location</h4>

<div class="search_location">

<input type="text" name="search_location" id="search_location" placeholder="Location"/>

</div>

</div>

<!-- Skills -->

<div class="widget">

<h4>Filter by Skills</h4>

<div class="search_categories resume-filter">

{!! Form::select('search_skills[]',$repository->filterSkills($candidates),null,['id'=>'search_skills','class'=>'chosen-select','multiple'=>'multiple']) !!}

</div>

</div>

<!-- Sub Category -->

<div class="widget">

<h4>Filter by Categories</h4>

<div class="search_categories resume-filter">

{!! Form::select('search_categories[]',$repository->filterSubCategory($candidates),null,['id'=>'search_categories','class'=>'job-manager-category-dropdown','multiple'=>'multiple']) !!}

</div>

</div>

<input type="submit" class="button big" value="Filter" />

</form>

The search criteria is:

  1. If filter by only one item (location or skills or categories) it will search only in that column and ignore other columns.
  2. If filter by two items it should match both column and ignore other.
  3. If filter by three/all it should match three columns.

I tried it in many different ways, my controller code is really messed up. So, I'm not posting it right now. Can anyone please help to build the query for filtering?

网友答案:

How about using conditionals on your controller checking which field is filled? So you can execute the proper query based on the current state of the search form.

分享给朋友:
您可能感兴趣的文章:
随机阅读: