Activity Logs

Activity logs are a great way for keeping track of what users are doing inside of your app. This allows you to view the user, affected models, and data that was submitted on particular dates.

In order to log new activity, simply use the activity() helper function:

$user = app(config('auth.providers.users.model'))->create($data);

activity('Created User: ' . $user->name, request()->all(), $user);

This helper will automatically attribute said activity to the currently logged in Auth user.

activity($message, $data = [], $model = null)

When logging an activity, be sure to specify the $message.

$data is optional, but is usually good to use the request()->all() method in order to populate it. It will automatically remove things like _method and _token from the array. Another thing to note is that you should never log any type of password information in the activity logger. Simply use array_except() on request()->all() if it contains sensitive data.

Finally, the $model is the model that was affected by the activity. You can simply pass in a model instance and it will automatically grab the class and id of said model so that it can be viewed in the activity log UI.

Viewing Activity Logs

Activity logs are accessible by going to the Activity Logs page in the admin panel. From here, you can view all of the logged activities as well as their details.