4

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?

4
  • Try to manage activity log of each query Commented Oct 13, 2017 at 8:03
  • 1
    use a audit table Commented Oct 13, 2017 at 8:05
  • 1
    I think the best one is to use model events if a user is updated then check if it is a sub manager who updated it then add a row in the activity table that you should create ;) Commented Oct 13, 2017 at 8:06
  • 1
    well you should have a log model .. where every action saves a log .. Commented Oct 13, 2017 at 9:21

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

@user7597883 If you like this answer you should consider accepting it
0

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

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.