Replies: 2 comments
-
Perhaps you can just check if there is an authenticated user? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Here's a few other ways you could theoretically achieve it, but to be honest, I don't like any of them. 😅 1 - Add context before running a job, and check that in the global scope // in AppServiceProvider
Queue::before(function () {
Context::add('environment', 'queue');
}); 2 - Force App::macro('setRunningInConsole', function (bool $value) {
$this->isRunningInConsole = $value;
return $this;
});
Queue::before(function () {
App::setRunningInConsole(true);
}); |
Beta Was this translation helpful? Give feedback.
0 replies
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
-
We are using global scopes to limit the access for some models for authenticated users to only their data. In the global scope we are using the authenticated user to limit the access they have to their own data.
However we also dispatch some jobs on the data where we do not care about the access. We therefore added the following code to the top of our global scopes:
if (App::runningInConsole()) { return; }
The problem now is that this check seems to be not true for jobs when using this package as it is a normal HTTP request for handling the job as far as I understand.
How can we still use this package with global scopes in a good way? Are there recommendations of how to detect if the global scope was called from a running job?
Beta Was this translation helpful? Give feedback.
All reactions