@@ -4,7 +4,6 @@ When creating record in Aureus ERP using Filament, you may need to modify form d
44
55This method allows you to:
66
7- - ** Automatically assign user-related fields** (e.g., ` creator_id ` , ` company_id ` ).
87- ** Set default values** for new records.
98- ** Modify or sanitize input data** before saving.
109
@@ -35,7 +34,6 @@ protected function mutateFormDataBeforeCreate(array $data): array
3534 $user = auth()->user();
3635
3736 $data['creator_id'] = $user->id;
38- $data['company_id'] = $user->default_company_id;
3937 $data['created_at'] = now();
4038
4139 return $data;
@@ -45,7 +43,6 @@ protected function mutateFormDataBeforeCreate(array $data): array
4543This ensures that:
4644
4745- ** The creator is assigned** (` creator_id ` ).
48- - ** The record belongs to the user's company** (` company_id ` ).
4946- ** The creation timestamp is set** (` created_at ` ).
5047
5148## ** Mutating Data in Modal Actions**
@@ -64,24 +61,24 @@ CreateAction::make()
6461 ]);
6562```
6663
67- ## ** Example: Implementing CreateProduct **
64+ ## ** Example: Implementing CreatePost **
6865
69- A ` CreateProduct ` class can be implemented using Filament’s ` CreateRecord ` .
66+ A ` CreatePost ` class can be implemented using Filament’s ` CreateRecord ` .
7067
7168``` php
7269<?php
7370
74- namespace Webkul\Inventory \Filament\Clusters\Products \Resources\ProductResource \Pages;
71+ namespace Webkul\Blog \Filament\Clusters\Posts \Resources\PostResource \Pages;
7572
7673use Filament\Notifications\Notification;
7774use Filament\Resources\Pages\CreateRecord;
7875use Illuminate\Support\Facades\Auth;
79- use Webkul\Inventory \Models\Product ;
80- use Webkul\Inventory \Filament\Clusters\Products \Resources\ProductResource ;
76+ use Webkul\Blog \Models\Post ;
77+ use Webkul\Blog \Filament\Clusters\Posts \Resources\PostResource ;
8178
82- class CreateProduct extends CreateRecord
79+ class CreatePost extends CreateRecord
8380{
84- protected static string $resource = ProductResource ::class;
81+ protected static string $resource = PostResource ::class;
8582
8683 protected function getRedirectUrl(): string
8784 {
@@ -92,33 +89,31 @@ class CreateProduct extends CreateRecord
9289 {
9390 return Notification::make()
9491 ->success()
95- ->title(__('Product created'))
96- ->body(__('Product has been created successfully.'));
92+ ->title(__('Post created'))
93+ ->body(__('Post has been created successfully.'));
9794 }
9895
9996 protected function mutateFormDataBeforeCreate(array $data): array
10097 {
10198 $user = Auth::user();
10299
103100 $data['creator_id'] = $user->id;
104- $data['company_id'] = $user->default_company_id;
105101 $data['created_at'] = now();
106102
107103 return $data;
108104 }
109105
110106 protected function afterCreate(): void
111107 {
112- ProductResource::updateStockLevels($this->getRecord());
113108 }
114109}
115110```
116111
117112## ** Explanation**
118113
119- - ** Handles Product Creation** : This class ensures proper product creation, following best practices.
114+ - ** Handles Post Creation** : This class ensures proper post creation, following best practices.
120115- ** Data Mutation** : Assigns the ` creator_id ` and ` company_id ` before saving.
121- - ** Post-Creation Processing** : Calls ` updateStockLevels() ` to recalculate stock availability after product creation.
122- - ** Redirection & Notifications** : Redirects to the product view and notifies the user on successful creation.
116+ - ** Post-Creation Processing** : Calls ` updateStockLevels() ` to recalculate stock availability after post creation.
117+ - ** Redirection & Notifications** : Redirects to the post view and notifies the user on successful creation.
123118
124119For more details, check the ** [ Official Filament Documentation] ( https://filamentphp.com/docs/3.x/panels/resources/creating-records ) ** . 🚀
0 commit comments