1. Go to this page and download the library: Download rmsramos/activitylog 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/ */
use Illuminate\Database\Eloquent\Model;
use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\Activitylog\LogOptions;
class NewsItem extends Model
{
use LogsActivity;
protected $fillable = ['name', 'text'];
public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
->logOnly(['name', 'text']);
}
}
use Rmsramos\Activitylog\ActivitylogPlugin;
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
ActivitylogPlugin::make(),
]);
}
use Rmsramos\Activitylog\ActivitylogPlugin;
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
ActivitylogPlugin::make()
->resource(\Path\For\Your\CustomResource::class),
]);
}
use Rmsramos\Activitylog\ActivitylogPlugin;
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
ActivitylogPlugin::make()
->label('Log')
->pluralLabel('Logs'),
]);
}
use Rmsramos\Activitylog\ActivitylogPlugin;
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
ActivitylogPlugin::make()
->navigationItem(false), // by default is true
]);
}
use Rmsramos\Activitylog\ActivitylogPlugin;
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
ActivitylogPlugin::make()
->navigationGroup('Activity Log'),
]);
}
use Rmsramos\Activitylog\ActivitylogPlugin;
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
ActivitylogPlugin::make()
->navigationIcon('heroicon-o-shield-check'),
]);
}
use Rmsramos\Activitylog\ActivitylogPlugin;
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
ActivitylogPlugin::make()
->navigationCountBadge(true),
]);
}
use Rmsramos\Activitylog\ActivitylogPlugin;
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
ActivitylogPlugin::make()
->navigationSort(3),
]);
}
use Rmsramos\Activitylog\ActivitylogPlugin;
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
ActivitylogPlugin::make()
->authorize(
fn () => auth()->user()->id === 1
),
]);
}
use App\Policies\ActivityPolicy;
use Illuminate\Support\Facades\Gate;
use Spatie\Activitylog\Models\Activity;
class AppServiceProvider extends ServiceProvider
{
public function boot(): void
{
Gate::policy(Activity::class, ActivityPolicy::class);
}
}
use Rmsramos\Activitylog\RelationManagers\ActivitylogRelationManager;
public static function getRelations(): array
{
return [
ActivitylogRelationManager::class,
];
}
use Rmsramos\Activitylog\Actions\ActivityLogTimelineTableAction;
public static function table(Table $table): Table
{
return $table
->actions([
ActivityLogTimelineTableAction::make('Activities'),
]);
}
public static function table(Table $table): Table
{
return $table
->actions([
ActivityLogTimelineTableAction::make('Activities')
->withRelations(['profile', 'address']), //opcional
]);
}