PHP code example of foxen / laravel-model-activity-log

1. Go to this page and download the library: Download foxen/laravel-model-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/ */

    

foxen / laravel-model-activity-log example snippets


use Illuminate\Database\Eloquent\Model;
use Foxen\LaravelModelActivityLog\Traits\LogsActivity;

class Post extends Model
{
    use LogsActivity;

    // ...
}

class Post extends Model
{
    use LogsActivity;

    protected $activityLogName = 'posts';

    // ...
}

class Post extends Model
{
    use LogsActivity;

    protected $ignoreActivityLogAttributes = ['updated_at'];

    // ...
}

class User extends Model
{
    use LogsActivity;

    protected $redactedActivityLogAttributes = ['password', 'remember_token'];

    // ...
}

use Foxen\LaravelModelActivityLog\Models\Activity;

// Get all activity for a specific model instance
$activities = Activity::whereSubject($post)->get();

// Get all activity for a specific model type
$activities = Activity::forSubjectType('App\Models\Post')->get();

// Get all activity caused by a specific user
$activities = Activity::whereCauser($user)->get();

// Get all activity for a specific causer type
$activities = Activity::forCauserType('App\Models\User')->get();

// Get all activity for a specific event
$activities = Activity::forEvent('created')->get();

$activity = Activity::first();

$subject = $activity->subject; // The model that was acted upon
$causer  = $activity->causer;  // The user who performed the action, or null

$activity = Activity::forEvent('updated')->first();

$old = $activity->properties['old']; // ['title' => 'Old Title']
$new = $activity->properties['new']; // ['title' => 'New Title']

// config/foxen_activitylog.php

return [
    // ...
    'prune_activity_log' => true,
    'prune_older_than_days' => 30,
];

use Illuminate\Support\Facades\Schedule;

Schedule::command('model:prune')->daily();
bash
php artisan vendor:publish --provider="Foxen\LaravelModelActivityLog\Providers\ActivityLogServiceProvider" --tag="config"
bash
php artisan migrate