-
Hi, I am looking for way to specify the middleware for all jobs. Right now we can add middleware to a job like: // app/Jobs/TestJob.php
public function middleware()
{
return [new PreventDuplicateJobMiddleware];
} What if we could do it globally for all Jobs/Mailables/Notifications etc // AppServiceProvider
Queue::middleware($arrayOfMiddleware) How to make it possible ? |
Beta Was this translation helpful? Give feedback.
Answered by
rojtjo
Feb 18, 2023
Replies: 1 comment 2 replies
-
I'm not sure if this is documented anywhere, but you can use the use Illuminate\Support\Facades\Bus;
Bus::pipeThrough([
SomeMiddleware::class,
new SomeOtherMiddlware(),
fn ($job, $next) => $next($job),
]); See: |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
ankurk91
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm not sure if this is documented anywhere, but you can use the
Bus::pipeThrough()
method for this:See:
https://github.com/laravel/framework/blob/10.x/src/Illuminate/Support/Facades/Bus.php#L21
https://github.com/laravel/framework/blob/10.x/src/Illuminate/Bus/Dispatcher.php#L270-L281