I am working with Laravel version 8, and I want to use the global scope to add a where clause to all queries of the User model.
/**
* The "booting" method of the model.
* @return void
*/
protected static function boot()
{
parent::boot();
if (!empty(Client::$Current_Token)) {
static::addGlobalScope(new ClientTokenScope);
}
}
Main Problem: The issue I'm facing is that the variable Client::$Current_Token I want to add to this global scope is not set when executing the boot method. This is because this variable is set in a middleware.
How can I resolve the issue so that when executing the boot method, the client token is set and not empty?