lundi 29 octobre 2018

laravel 5- get related products by search in Many To Many

Table 1: products: id,title
Table 2: features: id,name,values
Table 3:feature_product:id,product_id,values

I want get all related products when I search in values in feature_product table.

I do these:

in product model:

public function features()
{
    return $this->belongsToMany(Feature::class)->withPivot('values');
}

public function feature()
{
    // ???
}

and query for search:

 $q = 'yellow';
 $query->where(function($query) use ($q)
 {
    $query->WhereHas('feature' , function ($query) use 
    ($q){$query->where('values' , 'LIKE' , '%' . $q . '%' );});
 }

how can I search in related features of products? (and get those products)

I think I must do something in this function in product model:

public function feature()
{
        // ???
}



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2DaaWqV
via IFTTT

Aucun commentaire:

Enregistrer un commentaire