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