I have an Eloquent model called Vegetable with a global scope defined. The model is a subclass of another model I have created called Food that uses the same database table, and the global scope just limits the Vegetable class to working with foods that are vegetables. But the global scope defined in Vegetable seems to be applied to Food when Food is used in Vegetable's method. Is that expected behavior? If so, is there a way around it besides using withoutGlobalScope()
when necessary?
class Vegetable extends Food
{
...some code omitted
public function someMethod()
{
// this can't find the food unless it's a vegetable
$food = Food::find(1);
}
protected static function boot()
{
parent::boot();
static::addGlobalScope(new VegetableScope);
}
}