Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel events, are they executing synchronously?

basically what I want to do is use a special token auto login

but: only for a subset of pages. Say, commenting is ok with the token login. Changing credit card information and purchasing items is not ok with the token login.

So I want to store a boolean token_login on the users table.

On each login i set the token_login to false using the event handler

class EventServiceProvider extends ServiceProvider
{

    protected $listen = [
      'Illuminate\Auth\Events\Login' => [PostLoginListener::class],
    ];

When a true token login is performed, I set it to true.

So I expect the event to get called -> token_login = false

then code keeps running, setting token_login = true in case of the actual autologin.

Now this requires that the event actually always fires synchronously and always before the other code. Is that the case?

like image 803
Toskan Avatar asked Feb 07 '17 14:02

Toskan


1 Answers

As long as your PostLoginListener does not implement the Illuminate\Contracts\Queue\ShouldQueue interface, your event will be processed synchronously.

like image 64
patricus Avatar answered Sep 21 '22 00:09

patricus