F
Filament•4mo 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•4mo ago
Have a look at #awcodes-quick-create for a way to read the resource outside the current resource.
Gush
Gush•4mo ago
i did but i wanted to have it in table header instead, is it possible with the plugin?
awcodes
awcodes•4mo 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
More Posts
[Solved]: How to Hide "download csv file example"Hi everybody, i am working on importing a csv file, and i want to hide the "download csv file examplfilament-panels labels not "rendering"I installed filament in an existing project and I came across this problem. It looks like it doesn'tData for no longer existing block is kept in dataHello, When i remove a block from the form and re-save the resource. The removed block (php side) dSelect Field Required Wrong ValidationGuys, I'm trying to use Filament Form inside livewire component but I'm facing some errors related tRelationManager shows "Class must be declared abstract or implement method 'getTableQueryForExport'"In my RelationManagers my code editor shows "Class must be declared abstract or implement method 'geDefine table fixed table heightI'm trying to fix table height to specific size and get table records scrolling inside. How I can acIs it possible to load a table inside an Action Form?I need to provide more information to the user than is practical in a Select. Is it possible to retable action to open the relationship manager in a modal?I have UserResource and I want to have this "edit permissions" action to open the permissions relati1305 FUNCTION gpais.json_unquote does not existSQLSTATE[42000]: Syntax error or access violation: 1305 FUNCTION gpais.json_unquote does not exist The POST method is not supported for route admin/login. Supported methods: GET, HEAD.in production i have thiss error, there is my route : ``` GET|HEAD admin/login ................