F
Filament•9mo ago
Gush

Button to create model in other resources

Hey, im looking for a way to have a Action on a resource that is a create of the expecific model i want
4 Replies
🤖transistor🤖
if your models are related and it's not too complicated (too many fields or complex conditions), you could do something like this: https://filamentphp.com/docs/3.x/panels/resources/relation-managers#creating-related-records If you want to create a different model (not related) you could create a Filament action, something like this:
Forms\Components\Actions\Action::make('my action')
->action(function(MyModel $my_model, MyAction $my_action) {
$my_action->execute($my_model);
})
]),
Forms\Components\Actions\Action::make('my action')
->action(function(MyModel $my_model, MyAction $my_action) {
$my_action->execute($my_model);
})
]),
if you need more data than the model, you can inject Get or the livewire instance. Then in your Laravel app, create an Action directory and create an action:
<?php

namespace App\Actions;

use App\Models\MyModel;

class MyAction
{
public function execute(MyModel $my_model): void
{
// do something
// save MyModel
}
}
<?php

namespace App\Actions;

use App\Models\MyModel;

class MyAction
{
public function execute(MyModel $my_model): void
{
// do something
// save MyModel
}
}
awcodes
awcodes•9mo ago
Have a look at #awcodes-quick-create for a way to read the resource outside the current resource.
Gush
GushOP•9mo ago
i did but i wanted to have it in table header instead, is it possible with the plugin?
awcodes
awcodes•9mo ago
I mean to look at the code to see how it’s able to create actions for resources. And no the plugin itself it’s meant for tables.
Want results from more Discord servers?
Add your server