A package for log user login info

1.0.1 2020-03-25 19:15 UTC

This package is auto-updated.

Last update: 2022-05-16 18:53:55 UTC



English 中文

Build Status Scrutinizer Code Quality Code Coverage Code Intelligence Status Code Intelligence Status


  • Log user login records
  • Analyse user login logs



  • PHP 7.0+
  • Laravel 5.5+

You can install the package using composer

composer require moecasts/laravel-user-login-log

If you are using Laravel < 5.5, you need to add provider to your config/app.php providers array:


Publish the mirgrations file:

php artisan vendor:publish --tag=laravel-user-login-log-migrations

As optional if you want to modify the default configuration, you can publish the configuration file:

php artisan vendor:publish --tag=laravel-user-login-log-config

And create tables:

php artisan migrate


return [
     * cache avtive time (seconds)
    'expire' => 300,


Firstly, add LoginLoggable trait to your authenticatable model.

use Moecasts\Laravel\UserLoginLog\Traits\LoginLoggable;

class User extends Authenticatable
    use LoginLoggable;

Next, simply register the newly created class after auth middleware in your middleware stack.

// app/Http/Kernel.php

class Kernel extends HttpKernel
    protected $routeMiddleware = [
        'auth' => \App\Http\Middleware\Authenticate::class,
        // ...
        'login.log' => \Moecasts\Laravel\UserLoginLog\Middleware\UserLoginLogMiddleware::class,

    // ...

Finally, use the middleware:

Route::get('hello')->middleware(['auth', 'login.log']);


Get user's logs

$user = new User;

Create user login log

$user = new User;

Log when user newly login

This function is depet on cache, when your newly login, it will set a cache with for $seconds or default config ( loginlog.expire ) seconds when $seconds is not set.

$user = new User;
// $user->logLogin($seconds = null)

Check is new login

$user = new User;

Let's enjoy coding!