laravel - make a filter with relations

Posted 10 months ago by haizone

i have a product table with relations: "specValues"

in my product model:

public function specValues(){
    return $this->morphMany('App\Models\SpecValue', 'specvalued');

in my specValues in have:

class SpecValue extends Model
  use Cachable;

    protected $table = 'specvalued';

    protected $fillable = ['field_id', 'value', 'value_desc', 'link', 'specvalued_id', 'specvalued_type'];

    public $timestamps = false;

    public function specvalued()
        return $this->morphTo();
    public function field()
        return $this->belongsTo('App\Models\SpecField','field_id');

now i whant to make a filter and multi filter for the products list: with the "specvalued()" (from the specvalued table) i get the name (or id) and with the "value" fild" from the specvalued table

the specValues with product looks like this: ( i have alot like that but with a diffrent specvalued_id and value, and i whant a make a filter with that.

#attributes: array:8 [▼
            "id" => 354327
            "field_id" => 4
            "specvalued_id" => 27535 //(name = year)
            "specvalued_type" => "Model\Product"
            "value" => "2017"
            "value_desc" => null
            "link" => null
            "created_at" => "2017-09-03 10:12:30"

and i try to make somthing like that to get a products with spespic value from specValues table after filter:

$products = $category->products()->with('specValues')->
where ????

how i do the where options with my info?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.