How to override filament default form data store method
I'm looking to customize the default form data storage method in Filament. Specifically, I aim to direct the submitted form data to the CreateVehicle action class within the domain layer. Which function should I override to achieve this?
9 Replies
Hi. Just use the mutateFormDataBeforeCreate() method on the Create Page of your model.
https://filamentphp.com/docs/3.x/panels/resources/creating-records#customizing-the-creation-process
This doesn't work.. please help
Share some code
sure.
<?php
namespace App\Filament\Company\Resources\VehicleResource\Pages;
use App\Enums\Status;
use App\Filament\Company\Resources\VehicleResource;
use App\Models\Company;
use App\Models\VehicleCategory;
use App\Models\VehicleType;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Support\Facades\Auth;
use Localift\Vehicle\Actions\CreateVehicle as LocaliftCreateVehicle;
class CreateVehicle extends CreateRecord
{
protected static string $resource = VehicleResource::class;
public function __construct(
private LocaliftCreateVehicle $createVehicle
) {
}
protected function beforeCreate(): void
{
//dd($this->data['vehicle_category_id']);
$this->createVehicle->execute(
$this->data['name'],
Status::ACTIVE->toStatus(),
VehicleType::query()->find($this->data['vehicle_type_id'])->toVehicleType(),
VehicleCategory::query()->find($this->data['vehicle_category_id'])->toVehicleCategory(),
Company::query()->find(Auth::id())->toCompany(),
$this->data['name'],
);
}
}
error
I want data pass to CreateVehicle Action class.
Dont override the constructor, or call the parent constructor
Is missing
use below methodpublic function handleRecordCreation(array $data): Model
{
} Thank you everyone 🫡
} Thank you everyone 🫡