PHP code example of djl997 / filament-model-activity-page

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

    

djl997 / filament-model-activity-page example snippets


use Djl997\FilamentModelActivityPage\Traits\HasActivities;

class Company extends Model
{
    use HasActivities;
}

use Djl997\FilamentModelActivityPage\Pages\ActivityPage;

class Notes extends ActivityPage
{
    protected static string $resource = CompanyResource::class;

    protected function isPrivilegedUser(): bool
    {
        return auth()->user()->isAdmin();
    }

    protected function canSendInternalMessages(): bool
    {
        return auth()->user()->isAdmin();
    }

    protected function afterClientMessage(array $data): void
    {
        // Send notification, fire event, etc.
    }
}

public static function getPages(): array
{
    return [
        // ...
        'notes' => Notes::route('/{record}/notes'),
    ];
}

protected function getChildActivities(): array
{
    return $this->getRecord()->dossiers->map(fn ($dossier) => [
        'activities' => $dossier->activities,
        'context'    => $dossier->title,
    ])->all();
}

protected function resolveActivityIcon(array $activity): ?string
{
    // Show an envelope icon on event activities that contain "email" in the message
    if ($activity['level'] === 'event' && str_contains($activity['message'], 'email')) {
        return 'heroicon-m-envelope';
    }

    return null;
}

// config/filament-model-activity-page.php
return [
    'activity_model' => App\Models\Activity::class,

    'internal_scope_callback' => function (\Illuminate\Database\Eloquent\Builder $query) {
        if (auth()->check() && ! auth()->user()->isAdmin()) {
            $query->where('is_internal', false);
        }
    },
];

use Djl997\FilamentModelActivityPage\FilamentModelActivityPagePlugin;

->plugins([
    FilamentModelActivityPagePlugin::make(),
])
bash
php artisan vendor:publish --tag=filament-model-activity-page-migrations
php artisan migrate
bash
php artisan vendor:publish --tag=filament-model-activity-page-config