lumen-framework: Target [Illuminate\Contracts\Mail\Factory] is not instantiable.
- Lumen Version: 7.0.2
- PHP Version: 7.3.15
- Database Driver & Version: mysql
Description:
I am getting the following error when I run php artisan queue:work:
local.ERROR: Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Mail\Factory] is not instantiable. in ....../vendor/illuminate/container/Container.php:982
in my bootstrap/app.php I added
$app->configure('mail');
$app->alias('mailer', Illuminate\Mail\Mailer::class);
$app->alias('mailer', Illuminate\Contracts\Mail\Mailer::class);
$app->alias('mailer', Illuminate\Contracts\Mail\MailQueue::class);
$app->configure('queue');
$app->register(Illuminate\Mail\MailServiceProvider::class);
$app->register(Illuminate\Queue\QueueServiceProvider::class);
This is how I try to send my mail:
Mail::to($user)->locale(App::getLocale())->send(new Register($user));
and this is the Register class:
<?php
namespace App\Mail;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class Register extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;
/**
* The user instance.
*
* @var User
*/
protected $user;
/**
* Create a new message instance.
*
* @param User $user The user instance.
* @return void
*/
public function __construct(User $user)
{
$this->user = $user;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('emails.users.register');
}
}
Sending mails without queueing them works perfectly fine.
laravel/lumen-framework is version 7.x - illuminate/mail and illuminate/queue are both 7.3.0
Cheers 😉
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 19 (10 by maintainers)
Commits related to this issue
- Fix Mailer in Queue Same error: https://github.com/laravel/lumen-framework/issues/1057 — committed to FlusherDock1/library by FlusherDock1 2 years ago
- Fix Mailer in Queue (#584) Same error: https://github.com/laravel/lumen-framework/issues/1057 — committed to octobercms/library by FlusherDock1 2 years ago
I been fix the issue by adding this line
bootstrap/app.php
Thank you, working
The mail component now has a manager class.