Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

What you probably want to do is override the newQuery() function on the two models in question. Something like this:

class ProductType1
{
    public function newQuery($excludeDeleted = true)
    {
        return parent::newQuery()->whereType(1);
    }
}
class ProductType1
{
    public function newQuery($excludeDeleted = true)
    {
        return parent::newQuery()->whereType(2);
    }
}

I believe newQuery() is called in any instance where you use the query builder for that model, so that should work in all cases.

Last updated 2 years ago.
0

Wow, it works like a charm, thx thepsion5!

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

totha totha Joined 13 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.