Laravel Setting conditions for the morphMany collection

I have the following attitude towards people [/ p>

class Broker extends Eloquent{

    public function configurable(){
        return $this->morphTo();
    }
}

class ProductConfiguration extends Eloquent{

    public function productConfigurations()
    {
        return $this->morphMany('Excel\Products\ProductConfiguration','configurable');
    }
}

I can easily find all ProductConfigurations owned by the Broker by doing this:

    $broker = Broker::find($id);
    $productConfigurations = $broker->productConfigurations;

I do not understand how to define the conditions for ProductConfigurations, so if my ProductConfiguration has a field type, something like:

    $broker = Broker::find($id);
    $productConfigurations = $broker->productConfigurations->where('type' = 'reg');

Checking the documentation I can’t determine exactly how to do this.

+4
source share
1 answer

Well, it was just to temporarily freeze the brain or something else, it was that simple:

    $broker = Broker::find($id);    
    $configurations = $broker->productConfigurations()
            ->where('type',$type)
            ->get();;
+3
source

All Articles