Laravel 8 User Activity Log Status Example

Laravel

211

Sumit Suryavanshi

30-12-2020


Laravel 8 user activity log status example. In this tutorial, you will learn how to track user activity in laravel 8 app using package.

And i will show you step by step to track user activity and display in admin panel in laravel 8 app.

Laravel 8 User Activity Log Status Example

  • Install Laravel Application
  • Configure Database Detail
  • Run Migration
  • Install And Configure User Activity Log Package
  • Start Development Server

Install Laravel Application

First Step, you need to download or install laravel web application new setup on your local machine. you can use the following command to download or install laravel application new setup:

composer create-project laravel/laravel blog –-prefer-dist

If you want to install a specific version of laravel, you can follow the following tutorial

https://w3alert.com/laravel-tutorial/laravel-install-on-windows-ubuntu-with-composer

Configure Database Detail

After that, you will set up the database credentials in .env file. So open your .env file and update database credentials following:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=database_name
DB_USERNAME=root
DB_PASSWORD=root

Install Laravel UI

In step this, install LARAVEL ui package in laravel app by using the following command:

composer require laravel/ui

Install Bootstrap Auth Scaffolding

In step this, install auth scaffolding bootstrap package in laravel app by using the following command:

php artisan ui bootstrap --auth

Install Npm Packages

In step this, open again command prompt and type the following command to install node js:

npm install

Then type the following command on cmd to run npm:

npm run dev

Run Migration

Next, go to command prompt and run the following command:

php artisan migrate

OR

php artisan migrate:fresh

This php artisan migrate command creates a table in your database.

Install And Configure User Activity Log Package

In this step, open terminal and execute the following command to install user activity log package:

composer require haruncpi/laravel-user-activity

php artisan user-activity:install

After that, visit app/models directory and open user.php model and add the following line of code into it:

<?php

namespace App\Models;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Fortify\TwoFactorAuthenticatable;
use Laravel\Jetstream\HasProfilePhoto;
use Laravel\Sanctum\HasApiTokens;
use Haruncpi\LaravelUserActivity\Traits\Loggable;

class User extends Authenticatable
{
    use HasApiTokens;
    use HasFactory;
    use HasProfilePhoto;
    use Notifiable;
    use TwoFactorAuthenticatable;
     use Loggable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name',
        'email',
        'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password',
        'remember_token',
        'two_factor_recovery_codes',
        'two_factor_secret',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];

    /**
     * The accessors to append to the model's array form.
     *
     * @var array
     */
    protected $appends = [
        'profile_photo_url',
    ];
}

Start development server

You can use the following command artisan command to start the development server:

php artisan serve

The final step, go to your browser and type the below-given URL into your browser:

http://example.com/admin/user-activity