Muhammad Sipra
Muhammad Sipra

Reputation: 846

Audit users actions in Php laravel

I am developing admin section for the project in laravel 5. Where I have multiple administrators and a super admin. In this project, a super admin can audit the sub-administrators actions.

Now super admin wants to check that what are the other administrators doing on admin panel.

Example: An administrator updated user information like address, phone number or email. How super admin will come to know that which administrator did this and who was the user which was updated by the administrator.

What should be the best practice to do this should I save each and every action to the database table? or any best practice?

Upvotes: 4

Views: 1953

Answers (2)

Maikon Panazzolo
Maikon Panazzolo

Reputation: 23

Instead of create one Observer for each model as our frind said, you can create a single one passing the "Model" class as argument.

Upvotes: 0

user1436631
user1436631

Reputation:

You have to create a new table to store all the actions performed by admins.

Your new table should have fields to store following details

who - The person who performed an action

what - what action he/she performed(update, delete)

when - when the action is performed

on whom - on which user the action is performed

Now you have to create observers on all the models which you want to track(users)

see - laravel Observers

Your observer should have all the methods for actions which an admin performs(create, store, update, delete)

Your observer method should record the action performed by that admin to your newly created table.

Super admin can view the entries in this table to track admins behavior.

Upvotes: 2

Related Questions