PHP code example of jaocero / activity-timeline

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

    

jaocero / activity-timeline example snippets


use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use JaOcero\ActivityTimeline\Components\ActivityDate;
use JaOcero\ActivityTimeline\Components\ActivityDescription;
use JaOcero\ActivityTimeline\Components\ActivityIcon;
use JaOcero\ActivityTimeline\Components\ActivitySection;
use JaOcero\ActivityTimeline\Components\ActivityTitle;

public function infolist(Schema $schema): Schema
{
    return $schema
        ->state([
            'activities' => [
                ['title' => 'Published article', 'description' => 'Live on the blog.', 'status' => 'published', 'created_at' => now()],
                ['title' => 'Drafting article', 'description' => 'Writing the first draft.', 'status' => 'drafting', 'created_at' => now()->subDays(2)],
            ],
        ])
        ->components([
            ActivitySection::make('activities')
                ->label('My activities')
                ->description('These are the activities that have been recorded.')
                ->schema([
                    ActivityTitle::make('title'),
                    ActivityDescription::make('description'),
                    ActivityDate::make('created_at')->date('F j, Y'),
                    ActivityIcon::make('status')
                        ->icon(fn (?string $state): ?Heroicon => match ($state) {
                            'drafting' => Heroicon::OutlinedPencil,
                            'published' => Heroicon::OutlinedRocketLaunch,
                            default => null,
                        })
                        ->color(fn (?string $state): string => $state === 'published' ? 'success' : 'gray'),
                ]),
        ]);
}

ActivitySection::make('activities')
    ->aside()                 // Heading on the side, like an aside section
    ->contained(false)        // No card
    ->compact()               // Smaller nodes and tighter spacing
    ->headingVisible(false)
    ->groupByDate()           // "Today", "Yesterday" and date separators
    ->reverse()               // Oldest first
    ->showItemsCount(5)       // Reveal 5 items at a time, in the browser
    ->showItemsLabel('View older')
    ->showItemsIcon(Heroicon::ChevronDown)
    ->showItemsColor('primary')
    ->scrollOnShowMore(false) // Revealed items scroll into view by default
    ->loadMore('loadMoreActivities', hasMoreItems: fn (): bool => $this->hasMore) // Calls a Livewire method
    ->emptyStateHeading('No activities yet')
    ->emptyStateDescription('Check back later.')
    ->emptyStateIcon(Heroicon::OutlinedBoltSlash);

use JaOcero\ActivityTimeline\Components\ActivityLogSection;

public static function infolist(Schema $schema): Schema
{
    return $schema->components([
        // ...
        ActivityLogSection::make()
            ->limit(25)
            ->groupByDate(),
    ]);
}

ActivityLogSection::make()
    ->subject(fn (Order $record): Model => $record->customer)
    ->modifyQueryUsing(fn (Builder $query): Builder => $query->inLog('orders'))
    ->eventIcons(['shipped' => Heroicon::OutlinedTruck])
    ->eventColors(['shipped' => 'primary'])
    ->attributeLabels(['customer_id' => 'Customer'])
    ->formatChangeValueUsing(fn (mixed $value, string $attribute): mixed => $attribute === 'total' ? Number::currency($value / 100) : $value)
    ->getTitleUsing(fn (array $activity): string => $activity['description'])
    ->getDescriptionUsing(fn (array $activity): ?string => $activity['properties']['note'] ?? null);

use JaOcero\ActivityTimeline\Actions\ActivityTimelineAction;

->recordActions([
    ActivityTimelineAction::make()
        ->timeline(fn (ActivityLogSection $timeline): ActivityLogSection => $timeline->limit(100)),
])

use JaOcero\ActivityTimeline\Components\ActivityLogSection;
use JaOcero\ActivityTimeline\Pages\ActivityTimelinePage;

class ViewOrderActivities extends ActivityTimelinePage
{
    protected static string $resource = OrderResource::class;

    protected function getActivitiesPerPage(): int
    {
        return 20; // Older activities load with a "Load older activities" button
    }

    protected function configureActivitySection(ActivityLogSection $section): ActivityLogSection
    {
        return $section->eventIcons(['shipped' => Heroicon::OutlinedTruck]);
    }

    protected function modifyActivitiesQuery(Builder $query): Builder
    {
        return $query->inLog('orders');
    }
}

public static function getPages(): array
{
    return [
        // ...
        'activities' => Pages\ViewOrderActivities::route('/{record}/activities'),
    ];
}

Action::make('activities')
    ->url(fn (Order $record): string => OrderResource::getUrl('activities', ['record' => $record])),
bash
php artisan vendor:publish --tag=activity-timeline-translations