How to Check User Login Online Status & Last Seen in Laravel 8?

In this tutorial you will learn about the How to Check User Login Online Status & Last Seen in Laravel 8? and its application with practical example.

In this How to Check User Login Online Status and Last Seen in Laravel 8 tutorial I’ll show you how to check User Online, last seen and Not online in Laravel 8 using custom middleware. In this tutorial you will learn to check user is online or not in laravel. In this step by step guide we will be creating a custom middleware to check User Online, Not online and last seen.

How to Check User Login Online Status & Last Seen in Laravel 8?

In this step by step tutorial I will demonstrate you with example How to Check User Login Online Status and Last Seen in Laravel 8. Please follow the instruction given below:

  • Step 1: Install Laravel 8 App
  • Step 2: Connecting App to Database
  • Step 3: Generate Auth Scaffolding
  • Step 4: Add Column in User Table
  • Step 5: Create a Middleware
  • Step 6: Register Middleware in Kernel
  • Step 7: Create Controller by Artisan
  • Step 8: Check Online Status in Blade File
  • Step 9: Run Development Server

Step 1: Install Laravel 8 App

First of all we need to create a fresh laravel project, download and install Laravel 8 using the below command

Step 2: Connecting App to Database

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

Step 3: Generate Auth Scaffolding

In this step we will be generating laravel’s auth scaffolding using following command:

Step 4: Add Column in User Table

You need to add one column in the users table called last_seen. So, navigate database>migrations folder and open create_users_table file. Then update the last_seen column in this file as follow:


Now, run the migration to create database table using following artisan command:

Step 5: Create a Middleware

In this step we will creating custom middleware using following command:

Now, go to app>Http>Middleware and open ActivityByUser.php middleware. Then put the following code into your middleware file:

Step 6: Register Middleware in Kernel

In this step, navigate app>Http and open Kernel.php. And register ActivityByUser.php middleware in the kernal.php file. You can see as follow:

Step 7: Create Controller by Artisan

Now, lets create a controller named UserController using command given below –

Now, go to app>Http>Controllers and open UserController.php file. Then update the following method into your UserController.php file:

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

Step 8: Check Online Status in Blade File

Go to resources>views and open home.blade.php. Then update the following code into home.blade.php.

Step 9: Run Development Server

Now we are ready to run our example so lets start the development server using following artisan command –

In this tutorial we have learn about the How to Check User Login Online Status & Last Seen in Laravel 8? and its application with practical example. I hope you will like this tutorial.