Closed
Description
- Laravel Version: 8.X.X and 9.X.X
- PHP Version: 7.X and 8.X
- Database Driver & Version: All
Description:
When adding a global scope to the boot-method of a model and also using the query builder paginate for that same model, then the global scope is executed twice.
Steps To Reproduce:
- Add a global scope to your model:
protected static function boot()
{
parent::boot();
static::addGlobalScope(new MyGlobalScope());
}
- Run a query with paginate:
MyModel::where('id', '>', 0)->paginate(15);
- Result: MyGlobalScope is executed twice.
Execution backtrace #1:
1 =>
'file' => '/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php',
'function' => 'callScope',
'class' => 'Illuminate\\Database\\Eloquent\\Builder',
2 =>
'file' => '/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php',
'function' => 'applyScopes',
'class' => 'Illuminate\\Database\\Eloquent\\Builder',
3 =>
'file' => '/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php',
'function' => 'get',
'class' => 'Illuminate\\Database\\Eloquent\\Builder',
4 =>
'file' => '/var/www/html/app/MyTestFile.php',
'function' => 'paginate',
'class' => 'Illuminate\\Database\\Eloquent\\Builder',
Execution backtrace #2:
1 =>
'file' => '/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php',
'function' => 'callScope',
'class' => 'Illuminate\\Database\\Eloquent\\Builder',
2 =>
'file' => '/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php',
'function' => 'applyScopes',
'class' => 'Illuminate\\Database\\Eloquent\\Builder',
3 =>
'file' => '/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php',
'function' => 'toBase',
'class' => 'Illuminate\\Database\\Eloquent\\Builder',
4 =>
'file' => '/var/www/html/app/MyTestFile.php',
'function' => 'paginate',
'class' => 'Illuminate\\Database\\Eloquent\\Builder',
Metadata
Metadata
Assignees
Labels
No labels