Skip to content

Commit 1569e9f

Browse files
committed
feat: update documentation to reflect 'Posts' terminology; modify examples and code snippets accordingly
1 parent c6f6c77 commit 1569e9f

File tree

2 files changed

+73
-135
lines changed

2 files changed

+73
-135
lines changed
Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,84 @@
1-
# **Filtering Products Using Tabs**
1+
# **Filtering Posts Using Tabs**
22

3-
For filtering product records using **tabs** in the List page. You can define custom tabs in the `getTabs()` method.
3+
For filtering post records using **tabs** in the List page. You can define custom tabs in the `getTabs()` method.
44

55
## **Example Tabs:**
66

7-
- **All Products** → Displays all products.
8-
- **Archived** → Filters soft-deleted (trashed) products.
9-
- **Out of Stock** → Shows products with `stock = 0`.
7+
- **All Posts** → Displays all posts.
8+
- **Archived** → Filters soft-deleted (trashed) posts.
109

1110
**Code Example:**
1211

1312
```php
1413
public function getTabs(): array
1514
{
1615
return [
17-
'all' => Tab::make(__('All Products'))->badge(Product::count()),
18-
'archived' => Tab::make(__('Archived'))->badge(Product::onlyTrashed()->count())
16+
'all' => Tab::make(__('All Posts'))->badge(Post::count()),
17+
'archived' => Tab::make(__('Archived'))->badge(Post::onlyTrashed()->count())
1918
->modifyQueryUsing(fn ($query) => $query->onlyTrashed()),
2019
];
2120
}
2221
```
2322

24-
---
23+
## **2. Customizing the List Page for Posts**
2524

26-
## **2. Customizing the List Page for Products**
27-
28-
To customize how products are listed, you extend the `ListRecords` class.
25+
To customize how posts are listed, you extend the `ListRecords` class.
2926

3027
### **Key Features:**
3128

32-
- Define the **resource** (`ProductResource`).
33-
- Add **header actions**, such as a button to create new products.
29+
- Define the **resource** (`PostResource`).
30+
- Add **header actions**, such as a button to create new posts.
3431

3532
**Code Example:**
3633

3734
```php
38-
class ListProducts extends ListRecords
35+
class ListPosts extends ListRecords
3936
{
40-
protected static string $resource = ProductResource::class;
37+
protected static string $resource = PostResource::class;
4138

4239
protected function getHeaderActions(): array
4340
{
4441
return [
4542
Actions\CreateAction::make()
4643
->icon('heroicon-o-plus-circle')
47-
->label(__('New Product')),
44+
->label(__('New Post')),
4845
];
4946
}
5047
}
5148
```
5249

53-
---
54-
5550
## **3. Using Preset Views for Filtering**
5651

57-
Aureus ERP supports **preset views** to provide predefined product listings.
52+
Aureus ERP supports **preset views** to provide predefined post listings.
5853

5954
### **Example Preset Views:**
6055

61-
- **All Products** → Default view showing all records.
62-
- **Out of Stock** → Filters products with `stock = 0`.
63-
- **Archived** → Shows deleted products.
56+
- **All Posts** → Default view showing all records.
57+
- **Archived** → Shows deleted posts.
6458

6559
**Code Example:**
6660

6761
```php
6862
public function getPresetTableViews(): array
6963
{
7064
return [
71-
'all_products' => PresetView::make(__('All Products'))
65+
'all_posts' => PresetView::make(__('All Posts'))
7266
->icon('heroicon-s-clipboard-list')
7367
->favorite()
7468
->default()
7569
->modifyQueryUsing(fn (Builder $query) => $query),
76-
'out_of_stock' => PresetView::make(__('Out of Stock'))
77-
->icon('heroicon-s-exclamation-circle')
78-
->favorite()
79-
->modifyQueryUsing(fn (Builder $query) => $query->where('stock', 0)),
80-
'archived' => PresetView::make(__('Archived Products'))
70+
'archived' => PresetView::make(__('Archived Posts'))
8171
->icon('heroicon-s-archive-box')
8272
->favorite()
8373
->modifyQueryUsing(fn ($query) => $query->onlyTrashed()),
8474
];
8575
}
8676
```
8777

88-
---
89-
9078
## **Conclusion**
9179

9280
- Use **tabs** for quick filtering.
93-
- Customize the **list page** to include actions like product creation.
94-
- Implement **preset views** for predefined product filters.
81+
- Customize the **list page** to include actions like post creation.
82+
- Implement **preset views** for predefined post filters.
9583

9684
For more details, check the **[Official Filament Documentation](https://filamentphp.com/docs/3.x/panels/resources/listing-records)**. 🚀
Lines changed: 53 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,76 @@
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

55
This 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
2828
ChatterAction::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
8459
Actions\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

10075
use Barryvdh\DomPDF\Facade\Pdf;
10176
use Filament\Actions;
@@ -104,11 +79,11 @@ use Filament\Notifications\Notification;
10479
use Filament\Pages\SubNavigationPosition;
10580
use Filament\Resources\Pages\ViewRecord;
10681
use 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

183133
For more details, check the **[Official Filament Documentation](https://filamentphp.com/docs/3.x/panels/resources/viewing-records)**. 🚀

0 commit comments

Comments
 (0)