F
Filamentmatin rajabi

how to update another model instead of updating current resource?

hello i want to insert data into another model first when user edit a form. what should i do?
MR
matin rajabi17d ago
how to tell this function don't update any field?
PK
Povilas K17d ago
Maybe use Eloquent observers with updating() method (not updated()) that would execute before the update.
L
LeandroFerreira17d ago
sorry, what does it mean?
M
<Λmir>17d ago
I recommend handle this in the Model level. You may use an Eloquent observer and the updating/updated method. You also can check weather specific field has been updated by using wasChanged.
public function updated(Post $post): void
{
if ($post->wasChanged('title')) {
// Title field has been updated.
}
}
public function updated(Post $post): void
{
if ($post->wasChanged('title')) {
// Title field has been updated.
}
}
Note: The updating/updated methods will not called at all when no fields has been changed.
D
dissto16d ago
I suppose you could do something like this on your EditXXX class: (perhaps wrap it in a db transaction)
public function save(bool $shouldRedirect = true): void
{
// dd($this->data);
// do something here

parent::save($shouldRedirect);

}
public function save(bool $shouldRedirect = true): void
{
// dd($this->data);
// do something here

parent::save($shouldRedirect);

}
MR
matin rajabi16d ago
mamnun 😃 🤝 thanks for your help thanks for replying. problem solved thanks
Want results from more Discord servers?
Add your server
More Posts
Laravel-Filament Qr generateHello, I hope you have a good day. I want to make a QR converter based on Laravel-filament. I want aHow to download Export instead of storing on server?I have created an export header action on my table like this: ```php ->headerActions([ ExportActioWizard form submitSo im using wizard steps and in my form i have 3 steps but the "create" , "create and create anotherWidget table custom queryHi all, i've a widget that aims to show the latest casting like this: ```php class LatestCastings Policy not applying on custom actionI have a custom filament class that extends filament table action. Its purpose is to update the recoIncorrect orderingHello everybody. Guys, why is this ordering always wrong? The 1040 should come at the end and not atText overflow ellipsisHi all, I'am looking for a way to the size the textcolumn according to the screen size. If the sizeFill FileUpload with generated imagesIm trying to fill a FileUpload field with an image I generate using OpenAI's Dall e I added the reFilter from AccessorHello Together, i'm using Laravel Venture for Workflow Jobs, and i have set in my model a Accessor.Create action on custom pageI made a custom page and want to add a 'new' button to it. I added it, when i press it it shows an eLong time loading after click Action ModalHi, now Im facing the page took long time to load on landing, after click action, after submit. whtextareaHow to delete images in storage files when I delete my post in my blog from filament ?Checkbox image/select rowI have a table only with image column and actions. Like on this page https://demo.filamentphp.com/blFull width FilamentPHPI don't understand why, but since this morning on my whole application there is a problem : the menuMethod for allowing full HTML/Markup in Table ViewI'm attempting to create a ticketing program for my panel and thought it would make sense to use a tjson data in DB cast to object, seem not working in form, whyI save data as a json type to Mysql. In the model, when I cast to object, it won't read to Form. BuMedia Picker field typeI'm currently using Spatie's laravel-medialibrary package. I was wondering if there are any field tStill no way to hook into a modalCancelAction, right?As in do something after a requiresConfirmation() modal is canceled (either by clicking the x or theUsing an enum with a toggleDoes anyone know of a clean way to use enums with toggles? One of my models has a status column with->extremePaginationLinks() not working even as defaultThe link numbering and page index summary is not displaying and I've tried every possible thing I ca