activity-timeline

Usage

This plugin is already accessible within the Infolists builder and now supports both the ->state([]) and ->record() methods.

1public function activityTimelineInfolist(Infolist $infolist): Infolist
2{
3 return $infolist
4 ->state([
5 'activities' => [
6 [
7 'title' => "Published Article 🔥 - <span class='italic font-normal dark:text-success-400 text-success-600'>Published with Laravel Filament and Tailwind CSS</span>",
8 'description' => "<span>Approved and published. Here is the <a href='#' class='font-bold hover:underline dark:text-orange-300'>link.</a></span>",
9 'status' => 'published',
10 'created_at' => now()->addDays(8),
11 ],
12 [
13 'title' => 'Reviewing Article - Final Touches',
14 'description' => "<span class='italic'>Reviewing the article and making it ready for publication.</span>",
15 'status' => '',
16 'created_at' => now()->addDays(5),
17 ],
18 [
19 'title' => "Drafting Article - <span class='text-sm italic font-normal text-purple-800 dark:text-purple-300'>Make it ready for review</span>",
20 'description' => 'Drafting the article and making it ready for review.',
21 'status' => 'drafting',
22 'created_at' => now()->addDays(2),
23 ],
24 [
25 'title' => 'Ideation - Looking for Ideas 🤯',
26 'description' => 'Idea for my article.',
27 'status' => 'ideation',
28 'created_at' => now()->subDays(7),
29 ]
30 ]
31 ])
32 ->schema([
33 
34 /*
35 You should enclose the entire components within a personalized "ActivitySection" entry.
36 This section functions identically to the repeater entry; you simply have to provide the array state's key.
37 */
38 
39 ActivitySection::make('activities')
40 ->label('My Activities')
41 ->description('These are the activities that have been recorded.')
42 ->schema([
43 ActivityTitle::make('title')
44 ->placeholder('No title is set')
45 ->allowHtml(), // Be aware that you will need to ensure that the HTML is safe to render, otherwise your application will be vulnerable to XSS attacks.
46 ActivityDescription::make('description')
47 ->placeholder('No description is set')
48 ->allowHtml(),
49 ActivityDate::make('created_at')
50 ->date('F j, Y', 'Asia/Manila')
51 ->placeholder('No date is set.'),
52 ActivityIcon::make('status')
53 ->icon(fn (string | null $state): string | null => match ($state) {
54 'ideation' => 'heroicon-m-light-bulb',
55 'drafting' => 'heroicon-m-bolt',
56 'reviewing' => 'heroicon-m-document-magnifying-glass',
57 'published' => 'heroicon-m-rocket-launch',
58 default => null,
59 })
60 ->color(fn (string | null $state): string | null => match ($state) {
61 'ideation' => 'purple',
62 'drafting' => 'info',
63 'reviewing' => 'warning',
64 'published' => 'success',
65 default => 'gray',
66 }),
67 ])
68 ->showItemsCount(2) // Show up to 2 items
69 ->showItemsLabel('View Old') // Show "View Old" as link label
70 ->showItemsIcon('heroicon-m-chevron-down') // Show button icon
71 ->showItemsColor('gray') // Show button color and it supports all colors
72 ->aside(true)
73 ->compact() // remove section card chrome when nested in another container
74 ->headingVisible(true) // make heading visible or not
75 ->extraAttributes(['class'=>'my-new-class']) // add extra class
76 ]);
77}

When utilizing the ->record() function, you provide your model in a manner similar to the code showcased below:

1protected $activities;
2 
3public function __construct()
4{
5 $this->activities = User::query()->with('activities')->where('id', auth()->user()->id)->first();
6}
7 
8public function activityTimelineInfolist(Infolist $infolist): Infolist
9{
10 return $infolist
11 ->record($this->activities)
12 // ... remaining code
13}

Sometimes, when we don't have any info to show to users, it's important to improve their experience by displaying something. So, I include an empty state, like the one in the Filament Table Empty State.

1public function activityTimelineInfolist(Infolist $infolist): Infolist
2{
3 return $infolist
4 ->state([
5 'activities' => []
6 )]
7 ->schema([
8 ActivitySection::make('activities')
9 // ... other code
10 ->emptyStateHeading('No activities yet.')
11 ->emptyStateDescription('Check back later for activities that have been recorded.')
12 ->emptyStateIcon('heroicon-o-bolt-slash')
13 ])
14}

Usage with Spatie Activity Log Package

This plugin works with spatie/laravel-activitylog, making it easy to log user actions in your app. It can also automatically log model events, storing everything in the activity_log table. To use the plugin, just install spatie/laravel-activitylog, set it up, and you're good to go.

Creating a Custom Page

You are required to create a custom page within your resources to display all activities based on the record passed to the route.

1php artisan make:filament-page ViewOrderActivities --resource=OrderResource --type=custom

Including the Page in your Resource Class

Simply include the custom page in the getPages() method so that we can access it.

1public static function getPages(): array
2{
3 return [
4 // ... other pages
5 // The format of route doesn't matter, as long as it includes the route parameter {record}.
6 'activities' => Pages\ViewOrderActivities::route('/order/{record}/activities'),
7 ];
8}

In the actions method of your table, include an additional custom action. This action should redirect users to the custom page we've generated earlier.

1public static function table(Table $table): Table
2{
3 return $table
4 ->columns([
5 // ...
6 ])
7 ->filters([
8 // ...
9 ])
10 ->actions([
11 Tables\Actions\Action::make('view_activities')
12 ->label('Activities')
13 ->icon('heroicon-m-bolt')
14 ->color('purple')
15 ->url(fn ($record) => OrderResource::getUrl('activities', ['record' => $record])),
16 ])
17 ->bulkActions([
18 // ...
19 ]);
20}

Setting up your Custom Page

Changes are needed in your custom page. Instead of extending using the regular Page class will make use of a specific class called ActivityTimelinePage provided by the plugin. Additionally, you should include your resource class.

1use App\Filament\Resources\OrderResource;
2use LaraZeus\ActivityTimeline\Pages\ActivityTimelinePage;
3 
4class ViewOrderActivities extends ActivityTimelinePage
5{
6 protected static string $resource = OrderResource::class;
7}

Our Sponsors

Zeus is an open-source project. Thanks to our sponsors for helping maintain these packages.