# Laravel 5.4 - Laravel Users Online 2.2.x

## Instalation

Add the new required package in your composer.json

```
"highideas/laravel-users-online": "^2.2"
```
Run `composer update` or `php composer.phar update`.

Or install directly via composer

```
composer require highideas/laravel-users-online
```

After composer command, add new service provider in `config/app.php` :

```php
HighIdeas\UsersOnline\UsersOnlineServiceProvider::class,
HighIdeas\UsersOnline\Providers\UsersOnlineEventServiceProvider::class,
```

And add new middleware in `app/Http/Kernel.php` :

```php
\HighIdeas\UsersOnline\Middleware\UsersOnline::class,
```

After this, add the trait in your model User in `app/User.php`:

```php

class User extends Authenticatable
{
    use \HighIdeas\UsersOnline\Traits\UsersOnlineTrait;
...

```
Finally run `php artisan vendor:publish` for add the namespaces

## Usage

For show the users online just use the method `allOnline()`:

```php
$user = new User;
$user->allOnline();
```
Or if you want to check if a specific user is online use the method `isOnline()`:

```php
$user = User::find($id);
$user->isOnline();
```

You can sort all users online with the methods `mostRecentOnline()` and `leastRecentOnline()`:

```php
$user = new User;
$user->mostRecentOnline();
$user->leastRecentOnline();
```

