Helper Functions

There are a couple of helper functions that can be used in order to make your life easier.

flash($data = [])

Flashes data to the session so that an alert can be faded in and out on the next request. The use of an array in this function is important.

flash(['success', 'Role created!']);

The first array element contains the Bootstrap 4 alert- class e.g. success, andd the second contains the message that will be displayed.

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

Log a new activity in the database.

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

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

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.

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