I have project I'm building where I have a Shows page which I want to filtering by title. Each show contains data by title. if the data just data passive i can make it.
but my data now is, a data where i get when i create new data, like when i input new data. the filter list will get a new list.
here my controller :
public function getIndex()
{
$posts = DB::table('data_kos')
->orderBy('id', 'asc');
if (Request::get('q')) {
$posts->where('title','like','%'.Request::get('q').'%');
$posts->orwhere("sex","like","%".Request::get("q")."%");
$posts->orwhere("price","like","%".Request::get("q")."%");
}
if(Request::get("sex")) {
$posts = $posts->where("sex",Request::get("sex"));
}
if(Request::get("title")) {
$posts = $posts->where("title",Request::get("title"));
}
$posts = $posts->paginate(10);
return view('kost', ['posts' => $posts]);
}
and here my view :
<div class="btn-group">
<button type="button" class="btn btn-info">Filter By</button>
<button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu" role="menu">
@foreach($posts as $row)
<li><a href=""></a></li>
@endforeach
</ul>
</div>
then help me what code i need to add in my controller and my view ?
iam use laravel 5.1
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire