0

i have created a notification with ShouldQueue and my "job" table is populated but, when i launch a command: "php artisan queue:listen" the rows in table are processed but not send the email.

If don't use the queue all code function and email are send to destination.

I use the markdown for send email.

Command:

namespace App\Console\Commands;

use Illuminate\Console\Command;

//
use Notification;
use App\Notifications\Listini\NotifyListinoUpdate;

class StoreListinoOil extends Command
{
  /**
  * The name and signature of the console command.
  *
  * @var string
  */
  protected $signature = 'command:storelistinooil';

  /**
  * The console command description.
  *
  * @var string
  */


  /**
  * Create a new command instance.
  *
  * @return void
  */
  public function __construct()
  {
    parent::__construct();
  }

  /**
  * Execute the console command.
  *
  * @return mixed
  */
  public function handle()
  {

            $details = array(
              'day_listino' => 'today',
              'email' => '[email protected]'
            );



            Notification::send($details, new NotifyListinoUpdate($details));


    dd('OK'); 
  }
}

Notification -> NotifyListinoUpdate

namespace App\Notifications\Listini;

// use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
// use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
//
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class NotifyListinoUpdate extends Notification implements ShouldQueue
{
    // use Queueable;
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    private $details;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct($details)
    {
        $this->details = $details;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['mail'];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {

        return (new MailMessage)
        ->subject('Notifica - '.$this->details['day_listino'])
        ->markdown('mail.admin.listino_update',['details'=> $this->details]);
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}

1 Answer 1

0

You have to run the Queue worker using following command:

php artisan queue:work

Check the documentation on:

Running Queue Workers

Sign up to request clarification or add additional context in comments.

7 Comments

Have you set your queue connection to QUEUE_CONNECTION=database in .env file?
And also run these commands : php artisan queue:table php artisan migrate
Yes i have just exec queue:table and migrate. And i have set QUEUE_DRIVER=database in .env file!
If set QUEUE_CONNECTION=database the problem is the same.
You have to keep running "php artisan queue:work" while sending email.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.