Laravel 9 Check User Login, Online Status & Last Seen

In this tutorial you will learn about the Laravel 9 Check User Login, Online Status & Last Seen and its application with practical example.

In this Laravel 9 Check User Login, Online Status & Last Seen tutorial I’ll show you how to check User Online, last seen and Not online in Laravel 9 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 9?

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

  • Install Laravel 9
  • Connecting Database
  • Generate Auth Scaffolding
  • Add Column in User Table
  • Create a Middleware
  • Register Middleware in Kernel
  • Create Controller by Artisan
  • Check Online Status in Blade File
  • Run Development Server

Install Laravel 9

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

Connecting 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.

Generate Auth Scaffolding

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

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:

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:

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:

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

Check Online Status in Blade File

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

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 Laravel 9 Check User Login, Online Status & Last Seen and its application with practical example. I hope you will like this tutorial.