Laravel-activitylog (spatie) Installation with solved errors.

Sabaoon Bedar
3 min readJun 6, 2021

“Spatie” provides very useful and powerful packages to the laravel framework you might have seen many developers are struggling around to make role and permissions system, logs activity system and off-course it is time consuming. Spatie provided different packages for it. Similarly, one of the useful package that is activity log package provided by Spatie.

It is mentioned from the name that this package will help the system to get track of the activities that are happening or happened in the system. I write this article to help the developers in the installation process, the installation is given in the documentation as well but I will share the practical experience of mine in here and will show the errors you may face and how to tackle it. so, you are in the right place.

link of package: https://spatie.be/docs/laravel-activitylog/v4/introduction

Let’s jump into the installation process.

hint: laravel project installation | you can run below command

composer create-project — prefer-dist laravel/laravel yourproject

Step one: Access your root folder.

Open terminal on mac.
Bash or Cmd on windows.

cd <your folder location>

Check the below picture for help I reached to the root folder of my laravel application

accessed root folder

Now you can run your commands here and install the package to your laravel application.

Step 2: Install the package by copy and pasting the below command into your terminal or cmd.

composer require spatie/laravel-activitylog

Step 3: Install the migration they provided you.

php artisan vendor:publish --provider="Spatie\Activitylog\ActivitylogServiceProvider" --tag="activitylog-migrations"

You may face error like this or if not skip it|error:unable to locate publishable resources.

how to solve?

Solution

  1. First run command.
php artisan vendor:publish

You will see list of things to publish like

2. Select what you want to publish by giving the index number.| for package specific I selected the Tag migration with index 20. Just type 20 and enter.

20 

In your migrations folder you will be able to see your migration

Step 4: run command

php artisan migrate

if you are getting error in migrating the table due to mysql version, you only need to go to your migration and convert the json to the text.

make the above as :

$table->text('properties')->nullable();

Step 5: Now you have to publish the configuration.

php artisan vendor:publish --provider="Spatie\Activitylog\ActivitylogServiceProvider" --tag="activitylog-config"

Might you face the same error again repeat the above solution, but this time you have to select the config, 12 index.

In your config folder you will be able to see:

Use command

php artisan config:cache

Step 6: Add LogsActivity trait to your model of which you want to trace activity logs, in my case I would be adding this to my user model.

Congratulations ! you are done.

--

--

Sabaoon Bedar

Hello! I am a Software Engineer, experienced in Mobile and Web applications. Email: Baidar.sabaoon@gmail.com