Model of Category
public function lists(){
return $this->belongsToMany(listing::class);
}
Model of Listing
public function categories(){
return $this->belongsToMany(Category::class)->withPivot(['category_id','listing_id']); }
Controller: when i die dumb this query then i get all lists that is in listings table but i just want to get those lists whose have these categories
if($request->categories){
$var=$request->categories;//data in array 1,2,3
$lists =Listing::with(['categories' => function ($query) use($var) {
$query->whereIn('category_id',['=',$var]);
}])->get();
dd($lists);//
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3EmNP8J
via IFTTT
Aucun commentaire:
Enregistrer un commentaire