i have a project, in there i want to add filter feature. i can make it but i have a bug in my script. when i create new data booking in same title/post the filter list increases and have same title/post. but in there i just want to make a list of them.
Image
its should be :
- Kost Alpha Charlie Delta Echo
- Kost Fanta Bintaro
- Home Test
here is my controller :
public function getIndex()
{
$list = DB::table('data_kos')
->orderBy('id','asc')
->get();
$limit = 10;
$result = DB::table('data_kos')
->orderBy('id','asc');
if(Request::get('q')) {
$q = Request::input("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('title')) {
$result = $result->where("title",Request::get("title"));
}
$data['list'] = $list;
$data['posts'] = $result->paginate($limit);
return view('kost', $data);
}
and this is my view :
@foreach($list as $row)
<li><a href='{{ url("booking?title=$row->title") }}'>{{ $row->title }}</a></li>
@endforeach
what improvements do i have to make to the code to achieve my goal?