Answer the question
In order to leave comments, you need to log in
How to make a laravel filter?
I'm trying to implement a filter by three parameters.
view:
{{ Form::open(['route' => ['roll.index', 'method' => 'GET']]) }}
{{ Form::token() }}
<div class="input-group col-md-9">
{{ Form::select('catalog_id', \App\Models\Catalog::pluck('label','id'), null, ['placeholder' => 'Выберите каталог...', 'class' => 'form-control'])}}
{{ Form::select('category_id', \App\Models\RollCategory::pluck('label','id'), null, ['placeholder' => 'Выберите категорию...', 'class' => 'form-control'])}}
{{ Form::select('picture_id', \App\Models\RollPicture::pluck('label','id'), null, ['placeholder' => 'Выберите направление рисунка...', 'class' => 'form-control'])}}
<div class="input-group-append mb-3">
{{ Form::submit('Применить', ['class' => 'btn btn-primary']) }}
</div>
</div>
{{ Form::close() }}
public function scopeFilter($query)
{
if(request('catalog_id'))
{
$query->where('catalog_id', request('catalog_id'));
}
if(request('category_id'))
{
$query->where('category_id', request('category_id'));
}
if(request('picture_id'))
{
$query->where('picture_id', request('picture_id'));
}
return $query;
}
public function index(Request $request)
{
$rolls = RollStorage::with(['catalog', 'category', 'picture'])->filter()->paginate('10');
return view('admin.storage.roll.index', compact('rolls'));
}
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'category_id' cannot be null (SQL: insert into `roll_storages` (`catalog_id`, `category_id`, `picture_id`, `updated_at`, `created_at`) values (1, ?, ?, 2019-10-21 19:15:07, 2019-10-21 19:15:07))
Answer the question
In order to leave comments, you need to log in
Figured it out myself
{{ Form::open(['route' => 'roll.index', 'method' => 'GET']) }}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question