Reputation: 14931
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?
Upvotes: 9
Views: 6432
Reputation: 62278
As long as your PostLoginListener
does not implement the Illuminate\Contracts\Queue\ShouldQueue
interface, your event will be processed synchronously.
Upvotes: 18
Reputation: 726
Since PHP is a synchronous language (If you're not using HHVM or Hack), the events are always fired in the same order. So you can test whether or not this event fires before the other, and then go further from that.
Edit:
The way Laravel fires the events is largely based on the order in which your ServiceProvider array is stored inside config/app.php
.
Upvotes: 0