C
C
chelkaz2017-02-26 21:01:35
Laravel
chelkaz, 2017-02-26 21:01:35

Events queued through database, how to organize them correctly?

I added and generated an event and a listener:

protected $listen = [
        'App\Events\TestEvent' => [
            'App\Listeners\TestEventListener',
        ],
    ];

Next, in the desired controller, I call it:
event(new TestEvent($data));
Then I send it to the queue:
namespace App\Listeners;
use App\Events\TestEvent;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

class TestEventListener implements ShouldQueue
{
    public function __construct()
    {
        //
    }
    public function handle(TestEvent $event)
    {
        //
    }
}

After I see that queue is added to the jobs table in the database But what's next? Here I got confused ... I need that when an event is called in the controller, a variable from the event in the queue is sent to the mail. But in Laravel 5.4 everything was changed and now I'm confused. Unravel me with an example. It is necessary for me: Event after registration and sending of the letter to the User in queue.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav Nagorny, 2017-02-27
@esvils

It is necessary to run php artisan queue:workthat the queues would be executed
. Here is the dock.

public function handle(Mailer $mailer)
    {
        $mailer->send('email.welcome', ['data'=>'data'], function ($message) {

            $message->from('[email protected]', 'Christian Nwmaba');

            $message->to('[email protected]');

        });
    }

PS Everything is written in the dock
Job classes are very simple, usually containing only a handle method that is called when a job is queued.
Even with a translator it's more or less clear

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question