lumen-framework: Queueing mail throws an error
I’m trying to queue a mailable in Lumen 5.4, but run into a
FatalThrowableError in Mailable.php line 133:
Type error: Argument 1 passed to Illuminate\Mail\Mailable::queue() must be an instance of Illuminate\Contracts\Queue\Factory, null given, called in /home/vagrant/Code/.../vendor/illuminate/mail/Mailer.php on line 317
Using app('mailer')->to(env('MAIL_TO_ADDRESS'))->send(); works fine. I’ve checked that my mailable uses both Queueable and SerializesModels, extends Mailable and implements ShouldQueue. This might be related?
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 14
- Comments: 19 (2 by maintainers)
Working successfully by now. Thanks!
https://github.com/laravel/lumen-framework/issues/634
I have the same issue, any idea on a fix for this?
Further investigation:
in
bootstrap/app.phpbefore registering theMailServiceProvidergives me this:PHP message: PHP Fatal error: Maximum function nesting level of '256' reached, aborting! in /src/api/vendor/illuminate/container/Container.php on line 647Because inMailServiceProviderthis is used:which becomes an endless loop. If I DON’T register the
QueueServiceProviderI get the sameType error:as @michaeldzjap.EDIT: I fixed this in my own service provider, by explicitly setting
$mailer->setQueue($app['queue'])without registering theQueueServiceProviderinbootstrap/app.php.In my case for Lumen, It seems that it does not register the bindings for the
queueservice automatically - it’s lazily-loaded.See
registerQueueBindings()method.That method is only called when you issue an
$app->make('queue');call. You can refer to the following lines in the repository:https://github.com/laravel/lumen-framework/blob/5.5/src/Application.php#L893 https://github.com/laravel/lumen-framework/blob/5.5/src/Application.php#L219
What works for me is to make sure to call
$app->make('queue');before thequeueservice is first used.This issue is still not solved.Experiencing the same problem on lumen version 7 using beanstalkd queue. Error: Class ‘Illuminate\Mail\Mailable’ not found. Mail::send works fine.
All I had to do in Lumen was add
$app->make('queue');to mybootstrap/app.phpfile. I added it right after$app->withEloquent();. Anyone know if it’s okay there, or if it’s better to do it in a service provider as suggested above?I experiences the same issue and I found at least a workaround - basically create your own MailDispatcher job that takes care of the asynchronous sending of mails:
http://stackoverflow.com/questions/42203416/bindingresolutionexception-when-sending-mails-in-lumen-jobs
$app->make(‘queue’); I registered this in AppServiceProvider It is working also for me in lumen 8+
In app.php file add $app->make(‘queue’); It worked for me.
I was lucky enough to meet this problem, too. I submitted a pull request, but it was rejected.
From lumen 5.2, support for illuminate/mail is not ideal.
@aldee07 So can you make bound method work for?
Do
$this->app->make('queue')Then
$app->bound('queue')Works?
It seems amazing.