This is the documentation for
v2 but the latest version is
v4
.
You can switch versions in the menu on the left/at the top.
Check your current version with the following command:
composer show spatie/laravel-activitylog
##The default log
Without specifying a log name the activities will be logged on the default log.
activity()->log('hi');
$lastActivity = Spatie\Activitylog\Models\Activity::all()->last();
$lastActivity->log_name;
You can specify the name of the default log in the default_log_name
key of the config file.
##Specifying a log
You can specify the log on which an activity must be logged by passing the log name to the activity
function:
activity('other-log')->log("hi");
Activity::all()->last()->log_name;
##Specifying a log for each model
By default, the LogsActivity
trait uses default_log_name
from the config file to write the logs. You can set a different log for each model by setting the $logName
property on the model.
protected static $logName = 'custom_log_name_for_this_model';
##Retrieving activity
The Activity
model is just a regular Eloquent model that you know and love:
Activity::where('log_name' , 'other-log')->get();
There's also an inLog
scope you can use:
Activity::inLog('other-log')->get();
Activity::inLog('default', 'other-log')->get();
Activity::inLog(['default', 'other-log'])->get();