我有一个搜索表单,用于过滤多个选择框中的多个选项以过滤收入。在这里,我有一个' Accounts"我有的过滤器(现在正在工作)所有帐户或单个帐户过滤器。我需要的是能够根据用户选择筛选所有,单个或多个帐户。
我的表格:
{!! Form::open(['url' => 'incomes/revenues', 'role' => 'form', 'method' => 'GET']) !!}
<div class="pull-left">
<span class="title-filter hidden-xs">{{ trans('general.search') }}:</span>
<!--{!! Form::text('search', request('search'), ['class' => 'form-control input-filter input-sm', 'placeholder' => trans('general.search_placeholder')]) !!}-->
{!! Form::text('start', request('start'), ['class' => 'form-control input-filter input-sm','id' => 'datepicker', 'placeholder' => trans('general.date_placeholder')]) !!}
{!! Form::text('end', request('end'), ['class' => 'form-control input-filter input-sm','id' => 'datepicker1', 'placeholder' => trans('general.date_placeholder')]) !!}
{!! Form::select('customer', $customers, request('customer'), ['class' => 'form-control input-filter input-sm']) !!}
{!! Form::select('category', $categories, request('category'), ['class' => 'form-control input-filter input-sm']) !!}
{!! Form::select('account', $accounts, request('account'), ['multiple' => 'true','class' => 'form-control input-filter input-sm']) !!}
{!! Form::button('<span class="fa fa-filter"></span> ' . trans('general.filter'), ['type' => 'submit', 'class' => 'btn btn-sm btn-default btn-filter']) !!}
</div>
我的控制器
public function index()
{
$revenues = Revenue::with(['account', 'category', 'customer'])->isNotTransfer()->collect(['paid_at'=> 'desc']);
$customers = collect(Customer::enabled()->pluck('name', 'id'))
->prepend(trans('general.all_type', ['type' => trans_choice('general.customers', 2)]), '');
$categories = collect(Category::enabled()->type('income')->pluck('name', 'id'))
->prepend(trans('general.all_type', ['type' => trans_choice('general.categories', 2)]), '');
$accounts = collect(Account::enabled()->pluck('name', 'id')->toArray())
->prepend(trans('general.all_type', ['type' => trans_choice('general.accounts', 2)]), '');
$transfer_cat_id = Category::transfer();
return view('incomes.revenues.index', compact('revenues', 'customers', 'categories', 'accounts', 'transfer_cat_id'));
}
我的过滤器
public $relations = [];
public function search($query)
{
return $this->whereLike('description', $query);
}
public function start($start)
{
return $this->where('paid_at','>=' , $start);
}
public function end($end)
{
return $this->where('paid_at','<=' , $end);
}
public function customer($customer)
{
return $this->where('customer_id', $customer);
}
public function category($category)
{
return $this->where('category_id', $category);
}
public function account($account)
{
return $this->where('account_id', $account);
}
}
如果有人能告诉我如何实现这一点,将不胜感激。感谢。