I have a production ready API with laravel 11 and I want to integrate filament for some pretty views, but I want to integrate filament (create,update,list) with my existing API and not to default filament CRUD operation directly with models. For example I want to send create submit form to my API
p.s
Route::post('/teachers', [TeacherController::class, 'store']);
and edit to
Route::put('/teachers/{id}', [TeacherController::class, 'update']);
How can I integrate it ?
Thanks you anyway!
I use filament for the first time and I have no idea how to customize filament with existing API endpoints
please do not post any solution from chatGPT
3
Answers
Maybe something like this ? You can customize your actions:
you can change the create/update process, put your logic to call the existing API instead of actually creating the record using Eloquent
https://filamentphp.com/docs/3.x/panels/resources/creating-records#customizing-the-creation-process
https://filamentphp.com/docs/3.x/panels/resources/editing-records#customizing-the-saving-process
I would like to mention that filament has two types of resources
php artisan make:filament-resource Customer
as an examplephp artisan make:filament-resource Customer --simple
you can find more about that in the document filament documentation get started
assuming that you are working on the first type of resource, you would likely have a resource structure like this
so to customize the creation process go to App/Filament/Resource/PostResource/CreatePost
add the method
then add method to handle redirect
this is the way mentioned in the documentation check here
to handle the edit action go to App/Filament/Resource/PostResource/EditPost as example
handle the edit action redirect using the method
and again you can find all of these in the documentation cech here