I have 4 table here. I join them and i want to search a keyword by these colomn. I have see the result, but still there is few item that have dont match with criteria. Which is the criteria is wisata.publish = active
. So i did a foreach to eleminate the item that didn't match. But i did it, its reducing the amount of item in each page with pagination.
Any idea how to eleminate the items but dont reduce amount the items in each page. Or is the query wrong? Here my code.
$wisata = Wisata::leftJoin('kabupaten', 'kabupaten.id_kabupaten', '=', 'wisata.kabupaten_kota')
->leftJoin('kecamatan', 'kecamatan.id_kecamatan', '=', 'wisata.kecamatan')
->leftJoin('kelurahan', 'kelurahan.id_kelurahan', '=','wisata.kelurahan')
->where( function($query) use ($req) {
$query->where('wisata.nama_wisata','like', '%'.$req->keyword.'%')
->orwhere('wisata.alamat','like', '%'.$req->keyword.'%')
->orWhere('kabupaten.nama_kabupaten', 'LIKE', '%' .$req->keyword. '%')
->orWhere('kecamatan.nama_kecamatan', 'LIKE', '%' .$req->keyword. '%')
->orWhere('kelurahan.nama_kelurahan', 'LIKE', '%' .$req->keyword. '%');
})
->where('wisata.publish', '=', 1 )
->orderBy('wisata.nama_wisata', 'asc')
->paginate(6);
foreach($wisata as $index => $w )
{
if($w->publish == 0)
{
unset($wisata[$index]);
}
}
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/31Q84ay
via IFTTT
Aucun commentaire:
Enregistrer un commentaire