1. Go to this page and download the library: Download escarter/activity-log library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
escarter / activity-log example snippets
use Escarter\ActivityLog\Traits\LogsActivity;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
use LogsActivity;
// Optional: customize which events to log
public function shouldLogActivity(string $event): bool
{
// Only log creates and updates
return in_array($event, ['created', 'updated']);
}
}
use Escarter\ActivityLog\ActivityLogFacade as ActivityLog;
use Escarter\ActivityLog\DTOs\ActivityLogData;
// Using facade
ActivityLog::log(new ActivityLogData(
logName: 'orders',
description: 'Order was shipped',
subject: $order,
causer: auth()->user(),
event: 'shipped'
));
// Log model events
ActivityLog::logModel($model, 'archived', auth()->user());
// Log user login
ActivityLog::logLogin($user);
// In your routes/web.php
Route::middleware(['auth', 'admin'])->group(function () {
Route::get('/admin/activity-logs', function () {
return view('activity-log::livewire.admin-activity-log');
})->name('admin.activity-logs');
});
// In your routes/web.php
Route::middleware(['auth'])->group(function () {
Route::get('/my-activity', function () {
return view('activity-log::livewire.user-activity-log');
})->name('user.activity-logs');
});
protected function schedule(Schedule $schedule)
{
$schedule->command('activity-log:clean')->daily();
}