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

Most upvoted comments

I been fix the issue by adding this line

$app->alias('mail.manager', Illuminate\Mail\MailManager::class);
$app->alias('mail.manager', Illuminate\Contracts\Mail\Factory::class);

I been fix the issue by adding this line

$app->alias('mail.manager', Illuminate\Mail\MailManager::class);
$app->alias('mail.manager', Illuminate\Contracts\Mail\Factory::class);

Where did you add these lines? Can you explain why this fixes the issue?

bootstrap/app.php

I been fix the issue by adding this line

$app->alias('mail.manager', Illuminate\Mail\MailManager::class);
$app->alias('mail.manager', Illuminate\Contracts\Mail\Factory::class);

Thank you, working

The mail component now has a manager class.