In this tutorial you will learn about the Laravel 8 User Activity Log Tutorial and its application with practical example.
In this Laravel 8 User Activity Log Tutorial I will show you how to create user activity log in laravel 8 application. In this tutorial you will learn to create user activity log in laravel 8 application. You will also learn to delete user activity log in laravel 8 application. In this article we will be using haruncpi/laravel-user-activity log package for creating user activity log in laravel application. We will also be using boostrap ui and auth package for login, register, logout, reset password, forget password, email verification, two-factor authentication, session management.
Laravel 8 User Activity Log Tutorial
In this step by step tutorial to create user activity log in laravel 8 we will be using haruncpi/laravel-user-activity log package. Please follow instruction given below:
- Step 1 – Install Laravel 8 App
- Step 2 – Database Configuration
- Step 3 – Install Laravel UI
- Step 4 – Install Bootstrap Auth Scaffolding
- Step 5 – Install Npm Packages
- Step 6 – Install And Configure User Activity Log Package
- Step 7 – Run PHP artisan Migrate
- Step 8 – Run Development Server
- Step 9 – Test This App
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
1 |
composer create-project --prefer-dist laravel/laravel Blog |
Step 2 – Database Configuration
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.
1 2 3 4 5 6 |
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=db name DB_USERNAME=db user name DB_PASSWORD=db password |
Step 3 – Install Laravel UI
In this step we will now install laravel UI package using following command:
1 |
composer require laravel/ui |
Step 4 – Install Bootstrap Auth Scaffolding
Now, we will install auth scaffolding bootstrap package in laravel app by using the following command:
1 |
php artisan ui bootstrap --auth |
Step 5 – Install Npm Packages
In this step we will install npm dependencies using following command:
1 |
npm install |
Then type the following command on cmd to run npm:
1 |
npm run dev |
Step 6 – Install And Configure User Activity Log Package
In this step, we will install User Activity Log Package via the composer dependency manager. Use the following command to install User Activity Log Package
1 2 3 |
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
<?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', ]; } |
Step 7 – Run php artisan Migrate
Now, run following command to migrate database schema.
1 |
php artisan migrate |
Step 8 – Run Development Server
Now we are ready to run our example so lets start the development server using following artisan command –
1 |
php artisan serve |
Now, open the following URL in browser to see the output –
1 |
http://127.0.0.1:8000/ |