Laravel 5.2 : Do something after user has logged in?

You could try setting up event listeners for the Auth events that are fired.

You can setup a listener that listens for Illuminate\Auth\Events\Login to handle what you need post login and Illuminate\Auth\Events\Logout for post logout.

Laravel Docs - Authentication - Events


For the post login, you can do that by modifying App/Http/Controllers/Auth/AuthController.php

Add authenticated() into that class to override the default one:

use Illuminate\Http\Request;

protected function authenticated(Request $request, User $user) {
   // put your thing in here

   return redirect()->intended($this->redirectPath());
}

For the logout, add this function into the same class:

use Auth;

protected function getLogout()
{
    Auth::logout();

    // do something here

    return redirect('/');
}

For newer versions of Laravel

If you are only doing something very simple then creating an event handler seems overkill to me. Laravel has an empty method included in the AuthenticatesUsers class for this purpose.

Just place the following method inside app\Http\Controllers\LoginController (overriding it):

protected function authenticated(Request $request, $user)
{
    // stuff to do after user logs in
}

Alief's Answer below works fine as expected. But as i googled through, using the Event Handlers is probably the more preferred way. (It works like custom hooks).

So without any less respects to Alief's Answer below, let me choose --> this Event Handers approach i just found out.

Thanks all with regards!