Track Your Users Last Activity in Laravel

 Track Your Users Last Activity in Laravel

Track Your Users Last Activity in Laravel. We check the current user is authenticated. If the current user last_active_at date & time is NULL or is in the past, we want to update it using the current date and time. Forward the current request on to the next middleware.

Although there's many ways to do this in Laravel, the simplest way is with a piece of web middleware.

The setup

When an authenticated user visits a route in our application, we want to store the timestamp in the database for use later on. Let's store it in a column called last_active_at.

All you need to do is create a migration:

php artisan make:migration add_last_active_at_to_users_table --table=users

And add the following line in the up() method:

$table->timestamp('last_active_at')->nullable();

If the user has never visited a route, it will remain NULL in the database.

We also want to make sure this field is "fillable", so add last_active_at to the protected $fillable array on your User model.

As well as being able to update last_active_at using User::update(), we want to cast it to a Carbon\Carbon instance when using it so that we can make use of time comparison methods.

laravel

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Php how to delete multiple rows through checkbox using ajax in laravel

In this article i will let you know to delete multiple rows through checkbox using ajax in laravel and before delete we will give a confirmation message.

Top Laravel Development Company India | Laravel Development Services

As a Laravel development company, we use this framework to deliver robust & scalable customized Laravel web solutions & enterprise portals to global clients. 4200+ Projects | 16+ Yrs Exp | 97% Customer Retention

Hire Laravel Developers - Laravel Development Company

WebClues Infotech is a expert in building iOS, Android Apps, Web apps , Websites, Enterprise solutions. We have crafted many complex and innovative projects that meets our customer expectations.

How to Hire Laravel Developers and How Much Does It Cost.

Want to make the most out of the latest Laravel technology? Here is your guide on how to hire the best Laravel developer, and at the right price. 

How to perform migration rollback in laravel

Sometimes we need to rollback one specific migration. Here, in this article we will discuss about the migration rollback in laravel.