Laravel hasMany with where in a Polymorphic relationship

You can treat the relationship objects kind of like queries, in that you can call query building functions with them. The example below should get you going in the right direction.

class Cars extends Eloquent
{
    function photos()
    {
        return $this->hasMany('Photo')->where('photos.type', '=', 'Cars');
    }
}

Leave a Comment