When I try to Save a model from a EventHandler then the if( $event->save() )
always return false.
Any reason behind this? The $event is a user Model as I expect it to be.
<?php namespace AppName\Auth;
use Illuminate\Support\Facades\Hash;
class AuthEventHandler {
public function onUserLogin($event) {
$event->login_token = Hash::make('XXXX');
if( $event->save() ) {
dd(true);
} else {
dd(false);
}
}
public function onUserLogout($event) {
$event->login_token = null;
$event->save();
}
public function subscribe($events) {
$events->listen('auth.login', '\AppName\Auth\AuthEventHandler@onUserLogin');
$events->listen('auth.logout', '\AppName\Auth\AuthEventHandler@onUserLogout');
}
}