mardi 25 juillet 2017

Laravel 5.4 listener to save users login

I want to save via an event listener users login and I have the following code in a custom listener. When I try to get the id of the user it returns each time null. Is this approach how should I proceed or I am on the wrong track?

<?php

namespace App\Listeners;

use App\User;
use App\LoginLog;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Event;

class LogSuccessfulLogin
{


    protected $user;


    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct(User $user)
    {
        $this->user = $user;
    }

    /**
     * Handle the event.
     *
     * @param  IlluminateAuthEventsLogin  $event
     * @return void
     */
    public function handle($event)
    {

        var_dump($this->user->account_id);
        die;
            $login  = new LoginLog();

            $login->ip = \Request::ip();
            $login->notiz = 'login';
            $login->login_date = \Carbon\Carbon::now();
            $login->user = $this->user->account_id;

            $login->save();



    }
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire