11# ** Viewing Records**
22
3- When viewing record in Aureus ERP using Filament, you may need to customize the displayed data and allow users to perform actions like printing product details or deleting a product . Filament provides the ` ViewRecord ` class to handle viewing individual records.
3+ When viewing record in Aureus ERP using Filament, you may need to customize the displayed data and allow users to perform actions like publish and unpublish post status or deleting a post . Filament provides the ` ViewRecord ` class to handle viewing individual records.
44
55This class allows you to:
66
7- - ** Display product details** in a structured manner.
8- - ** Allow users to print product labels** in different formats.
9- - ** Provide an option to delete a product ** with success notifications.
7+ - ** Display post details** in a structured manner.
8+ - ** Allow users to publish and unpublish post labels** in different formats.
9+ - ** Provide an option to delete a post ** with success notifications.
1010
1111## ** Usage Example**
1212
1313### ** Basic Implementation**
1414
1515``` php
16- protected static string $resource = ProductResource ::class;
16+ protected static string $resource = PostResource ::class;
1717```
1818
19- This links the ` ViewProduct ` class to the ` ProductResource ` .
19+ This links the ` ViewPost ` class to the ` PostResource ` .
2020
2121## ** Actions Available in View Mode**
2222
2323### ** 1. Chatter Action**
2424
25- Allows users to discuss product details within the application.
25+ Allows users to discuss post details within the application.
2626
2727``` php
2828ChatterAction::make()->setResource(static::$resource),
2929```
3030
31- ### ** 2. Print Action **
31+ ### ** 2. Publish and Unpublish Actions **
3232
33- Allows users to generate and print product labels in different formats .
33+ Allows users to update post status to publish and unpublish .
3434
3535``` php
36- Actions\Action::make('print')
37- ->label(__('Print Product'))
38- ->color('gray')
39- ->icon('heroicon-o-printer')
40- ->form([
41- Forms\Components\TextInput::make('quantity')
42- ->label(__('Quantity'))
43- ->required()
44- ->numeric()
45- ->minValue(1)
46- ->maxValue(100),
47- Forms\Components\Radio::make('format')
48- ->label(__('Print Format'))
49- ->options([
50- 'dymo' => __('Dymo Label'),
51- '2x7_price' => __('2x7 Price Tag'),
52- '4x7_price' => __('4x7 Price Tag'),
53- '4x12' => __('4x12 Label'),
54- '4x12_price' => __('4x12 Price Label'),
55- ])
56- ->default('2x7_price')
57- ->required(),
58- ])
59- ->action(function (array $data, $record) {
60- $pdf = \Barryvdh\DomPDF\Facade\Pdf::loadView('products::filament.resources.products.actions.print', [
61- 'records' => collect([$record]),
62- 'quantity' => $data['quantity'],
63- 'format' => $data['format'],
64- ]);
65-
66- $paperSize = match ($data['format']) {
67- 'dymo' => [0, 0, 252.2, 144],
68- default => 'a4',
69- };
70-
71- $pdf->setPaper($paperSize, 'portrait');
72-
73- return response()->streamDownload(function () use ($pdf) {
74- echo $pdf->output();
75- }, 'Product-'.$record->name.'.pdf');
36+ Actions\Action::make('publish')
37+ ->label(__('Publish'))
38+ ->color('primary')
39+ ->icon('heroicon-o-check-badge')
40+ ->visible(fn($record) => $record->status == PostStatus::UNPUBLISHED->value)
41+ ->action(function ($record) {
42+ $record->update(['status' => PostStatus::PUBLISHED->value])
43+ }),
44+ Actions\Action::make('un_publish')
45+ ->label(__('Unpublish'))
46+ ->color('primary')
47+ ->icon('heroicon-o-x-circle')
48+ ->visible(fn($record) => $record->status == PostStatus::PUBLISHED->value)
49+ ->action(function ($record) {
50+ $record->update(['status' => PostStatus::UNPUBLISHED->value])
7651 }),
7752```
7853
7954### ** 3. Delete Action**
8055
81- Allows users to delete the product with a success notification.
56+ Allows users to delete the post with a success notification.
8257
8358``` php
8459Actions\DeleteAction::make()
8560 ->successNotification(
8661 Notification::make()
8762 ->success()
88- ->title(__('Product Deleted'))
89- ->body(__('Product has been deleted successfully.')),
63+ ->title(__('Post Deleted'))
64+ ->body(__('Post has been deleted successfully.')),
9065 ),
9166```
9267
93- ## ** Final ` ViewProduct ` Implementation**
68+ ## ** Final ` ViewPost ` Implementation**
9469
9570``` php
9671<?php
9772
98- namespace Webkul\Product \Filament\Resources\ProductResource \Pages;
73+ namespace Webkul\Post \Filament\Resources\PostResource \Pages;
9974
10075use Barryvdh\DomPDF\Facade\Pdf;
10176use Filament\Actions;
@@ -104,11 +79,11 @@ use Filament\Notifications\Notification;
10479use Filament\Pages\SubNavigationPosition;
10580use Filament\Resources\Pages\ViewRecord;
10681use Webkul\Chatter\Filament\Actions\ChatterAction;
107- use Webkul\Product \Filament\Resources\ProductResource ;
82+ use Webkul\Post \Filament\Resources\PostResource ;
10883
109- class ViewProduct extends ViewRecord
84+ class ViewPost extends ViewRecord
11085{
111- protected static string $resource = ProductResource ::class;
86+ protected static string $resource = PostResource ::class;
11287
11388 public function getSubNavigationPosition(): SubNavigationPosition
11489 {
@@ -119,53 +94,28 @@ class ViewProduct extends ViewRecord
11994 {
12095 return [
12196 ChatterAction::make()->setResource(static::$resource),
122- Actions\Action::make('print')
123- ->label(__('Print Product'))
124- ->color('gray')
125- ->icon('heroicon-o-printer')
126- ->form([
127- Forms\Components\TextInput::make('quantity')
128- ->label(__('Quantity'))
129- ->required()
130- ->numeric()
131- ->minValue(1)
132- ->maxValue(100),
133- Forms\Components\Radio::make('format')
134- ->label(__('Print Format'))
135- ->options([
136- 'dymo' => __('Dymo Label'),
137- '2x7_price' => __('2x7 Price Tag'),
138- '4x7_price' => __('4x7 Price Tag'),
139- '4x12' => __('4x12 Label'),
140- '4x12_price' => __('4x12 Price Label'),
141- ])
142- ->default('2x7_price')
143- ->required(),
144- ])
145- ->action(function (array $data, $record) {
146- $pdf = Pdf::loadView('products::filament.resources.products.actions.print', [
147- 'records' => collect([$record]),
148- 'quantity' => $data['quantity'],
149- 'format' => $data['format'],
150- ]);
151-
152- $paperSize = match ($data['format']) {
153- 'dymo' => [0, 0, 252.2, 144],
154- default => 'a4',
155- };
156-
157- $pdf->setPaper($paperSize, 'portrait');
158-
159- return response()->streamDownload(function () use ($pdf) {
160- echo $pdf->output();
161- }, 'Product-'.$record->name.'.pdf');
97+ Actions\Action::make('publish')
98+ ->label(__('Publish'))
99+ ->color('primary')
100+ ->icon('heroicon-o-check-badge')
101+ ->visible(fn($record) => $record->status == PostStatus::UNPUBLISHED->value)
102+ ->action(function ($record) {
103+ $record->update(['status' => PostStatus::PUBLISHED->value])
162104 }),
105+ Actions\Action::make('un_publish')
106+ ->label(__('Unpublish'))
107+ ->color('primary')
108+ ->icon('heroicon-o-x-circle')
109+ ->visible(fn($record) => $record->status == PostStatus::PUBLISHED->value)
110+ ->action(function ($record) {
111+ $record->update(['status' => PostStatus::UNPUBLISHED->value])
112+ }),,
163113 Actions\DeleteAction::make()
164114 ->successNotification(
165115 Notification::make()
166116 ->success()
167- ->title(__('Product Deleted'))
168- ->body(__('Product has been deleted successfully.')),
117+ ->title(__('Post Deleted'))
118+ ->body(__('Post has been deleted successfully.')),
169119 ),
170120 ];
171121 }
@@ -174,10 +124,10 @@ class ViewProduct extends ViewRecord
174124
175125## ** Explanation**
176126
177- - ** Handles Product Viewing** : Displays product details in a structured format.
178- - ** Print Product Feature** : Allows printing labels in different formats .
179- - ** Delete Product Feature** : Provides an option to delete a product with notifications.
180- - ** Chatter Integration** : Enables discussion around the product .
127+ - ** Handles Post Viewing** : Displays post details in a structured format.
128+ - ** Publish and Unpublished Post Feature** : Allows users to publish and unpublished post status .
129+ - ** Delete Post Feature** : Provides an option to delete a post with notifications.
130+ - ** Chatter Integration** : Enables discussion around the post .
181131- ** Navigation Position** : Places the page navigation at the top.
182132
183133For more details, check the ** [ Official Filament Documentation] ( https://filamentphp.com/docs/3.x/panels/resources/viewing-records ) ** . 🚀
0 commit comments