How to create items based on a submit form?

Hello, I have done my CRUD to make events, and inside that there is a relation to create "inscriptions", for each inscription I made, i want to create "4 quotes" on the table "quotes", how to do that? Let's say: - events id, name -inscriptions id, client_id, event_id -quotes id, value, date Once i create inscription i want to create different quotes. Thanks
6 Replies
krekas
krekas16mo ago
you could use afterCreate() method
metelidrissi
metelidrissiOP16mo ago
Thanks, so it means inside the file EventCreate.php i have to put that: protected function afterCreate(): void { // Runs after the form fields are saved to the database. } ? Where's the best place to put afterCreate? As I see it only works for Event, but i want to create after Relation, how to do that?
Brian Kidd
Brian Kidd16mo ago
I would do this using standard Laravel model events or dispatch a custom event after creation - I personally wouldn’t rely on Filament unless there was a good reason to do so. https://laravel.com/docs/10.x/eloquent#events
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
metelidrissi
metelidrissiOP16mo ago
Hi Brian, thanks it works great using static function booted() inside the Model Inscription.php The truth is that I find it very interesting to do basic CRUD, but sometimes maybe because I'm from the old school, I don't quite understand how the frontend part works, if I want to add a button to do something in other projects it's like it works more by scalpel, here you have to make an abstraction of everything and adapt to what the tool offers you.
krekas
krekas16mo ago
The thing is you need to learn laravel pretty good first, then livewire at least basics and only then jump to filament
metelidrissi
metelidrissiOP16mo ago
To be honest, I have been coming from Codeigniter for many years, I have tried more than once to make the jump to Laravel, since I clearly see its advantages. This is the first time I have seen things easy, and it has been precisely thanks to FilamentPHP
Want results from more Discord servers?
Add your server