PHP code example of digitalindoorsmen / laravel-actor-trails

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

    

digitalindoorsmen / laravel-actor-trails example snippets


use DigitalIndoorsmen\LaravelActorTrails\Traits\HasActorTrails;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Post extends Model
{
    use HasActorTrails, SoftDeletes;

    protected $fillable = ['title', 'body'];
}

$post = Post::create(['title' => 'Hello World']);

// Example created_by value:
[
  "id" => 1,
  "user_type" => "User",
  "auth_table" => "users",
  "display_name" => "Alice"
]

return [
    'attributes' => [
        'id' => fn($user) => $user->getAuthIdentifier(),
        'user_type' => fn($user) => class_basename($user),
        'auth_table' => fn($user) => $user->getTable(),
        'display_name' => fn($user) => $user->name ?? $user->username ?? 'Unknown',
    ],
];
bash
php artisan actor-trails:add posts
php artisan migrate