PHP code example of riodwanto / filament-logger

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

    

riodwanto / filament-logger example snippets




namespace App\Providers;

use Filament\Panel;
use Filament\PanelProvider;

class AdminPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            ->resources([
                config('filament-logger.activity_resource')
            ]);
    }
}

return [
    'datetime_format' => 'd/m/Y H:i:s',
    'date_format' => 'd/m/Y',
    'activity_resource' => \Riodwanto\FilamentLogger\Resources\ActivityResource::class,
    'scoped_to_tenant' => true,
    'navigation_sort' => null,
];

'resources' => [
    'enabled' => true,
    'log_name' => 'Resource',
    'logger' => \Riodwanto\FilamentLogger\Loggers\ResourceLogger::class,
    'color' => 'success',
    'exclude' => [
        // App\Filament\Resources\UserResource::class,
    ],
    'cluster' => null,
    'navigation_group' => 'Settings',
],

'access' => [
    'enabled' => true,
    'logger' => \Riodwanto\FilamentLogger\Loggers\AccessLogger::class,
    'color' => 'danger',
    'log_name' => 'Access',
],

'notifications' => [
    'enabled' => true,
    'logger' => \Riodwanto\FilamentLogger\Loggers\NotificationLogger::class,
    'color' => null,
    'log_name' => 'Notification',
],

'models' => [
    'enabled' => true,
    'log_name' => 'Model',
    'color' => 'warning',
    'logger' => \Riodwanto\FilamentLogger\Loggers\ModelLogger::class,
    'register' => [
        // App\Models\User::class,
        // App\Models\Post::class,
    ],
],

'custom' => [
    [
        'log_name' => 'Payment',
        'color' => 'primary',
        'logger' => \App\Loggers\PaymentLogger::class,
    ],
],



namespace App\Loggers;

use Riodwanto\FilamentLogger\Loggers\AbstractModelLogger;

class PaymentLogger extends AbstractModelLogger
{
    protected function getLogName(): string
    {
        return 'Payment';
    }
    
    public function paymentProcessed($payment)
    {
        $this->log($payment, 'Processed', 'Payment was processed successfully');
    }
}

'resources' => [
    'exclude' => [
        \App\Filament\Resources\UserResource::class,
        \App\Filament\Resources\ActivityResource::class,
    ],
],

// In your config
'navigation_group' => 'Audit',
'navigation_sort' => 10,
'scoped_to_tenant' => false, // Set to false for global logs

'datetime_format' => 'Y-m-d H:i:s', // Database format
'date_format' => 'Y-m-d',          // Display format

use Filament\Tables\Actions\BulkAction;

// In your ActivityResource table method
BulkAction::make('export')
    ->label('Export Selected')
    ->icon('heroicon-o-download')
    ->action(function ($records) {
        // Your export logic here
    }),

// In your config/filament-logger.php
'debug' => env('FILAMENT_LOGGER_DEBUG', false),


 
namespace App\Providers;
 
use App\Policies\ActivityPolicy;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Spatie\Activitylog\Models\Activity;
 
class AuthServiceProvider extends ServiceProvider
{
    protected $policies = [
        // Update `Activity::class` with the one defined in `config/activitylog.php`
        Activity::class => ActivityPolicy::class,
    ];
    //...
}
bash
php artisan filament-logger:install
bash
php artisan migrate
bash
php artisan vendor:publish --tag="filament-logger-translations"
bash
php artisan vendor:publish --tag="filament-logger-translations"
bash
   php artisan config:clear
   php artisan cache:clear