I would like to chain 2 global scopes which are accessible through traits I made.
trait ActivatedTrait
{
public static function bootActivatedTrait()
{
static::addGlobalScope(new ActivatedScope);
}
public static function withInactive()
{
$instance = new static;
return $instance->newQueryWithoutScope(new ActivatedScope);
}
}
trait PublishedTrait
{
public static function bootPublishedTrait()
{
static::addGlobalScope(new PublishedScope);
}
public static function withUnpublished()
{
$instance = new static;
return $instance->newQueryWithoutScope(new PublishedScope);
}
}
When I call my model like this, it works
MyModel::withInactive()
MyModel::withUnpublished()
But this doesn't
MyModel::withInactive()->withUnpublished()
EDIT
For some reason, this code worked under Laravel 4.2, but I switched to 5.5 and now it broke.
EDIT 2
If I make local scopes like scopeWithInactive()
and scopeWithUnpublished()
I can chain them just fine.