julianwayu
julianwayu
FFilament
Created by julianwayu on 7/4/2024 in #❓┊help
CreateAction with form() how to use different model than the current one.
So I have a tasks table that lists different tasks and have actions that you can take on different resources. For example i have a task that it's "add track" and i have a form that creates tracks that i'm using in the manage tracks resource. I extracted it as a shared form and now i'm able to add it to this specific task as such:
Tables\Actions\Action::make('Add Track')
->form(TrackForm::schema())
->icon('iconoir-plus-circle')
Tables\Actions\Action::make('Add Track')
->form(TrackForm::schema())
->icon('iconoir-plus-circle')
When i click on the action button i get the following error [object] (BadMethodCallException(code: 0): Call to undefined method App\Models\Task::trackArtists() this is the track form schema:
class TrackForm
{

public static function schema()
{
return [
Forms\Components\TextInput::make('name')
->columnSpan(2)
->required(),
Forms\Components\Repeater::make('trackArtists')
->relationship()
->hiddenLabel()
->columnSpanFull()
->columns([
'sm' => 4,
])
->schema([
Forms\Components\Select::make('artist_id')
->relationship('artist', 'name')
->getOptionLabelUsing(fn ($value): ?string => Artist::find($value)?->name)
->searchable()
),
];
}
}
class TrackForm
{

public static function schema()
{
return [
Forms\Components\TextInput::make('name')
->columnSpan(2)
->required(),
Forms\Components\Repeater::make('trackArtists')
->relationship()
->hiddenLabel()
->columnSpanFull()
->columns([
'sm' => 4,
])
->schema([
Forms\Components\Select::make('artist_id')
->relationship('artist', 'name')
->getOptionLabelUsing(fn ($value): ?string => Artist::find($value)?->name)
->searchable()
),
];
}
}
I understand the problem and it's that the form its thinking that it needs to use the model from the current resource which is "tasks" I tried something like this:
Tables\Actions\Action::make('Add Track')
->model(Track::class)
->form(TrackForm::schema())
->icon('iconoir-plus-circle')
Tables\Actions\Action::make('Add Track')
->model(Track::class)
->form(TrackForm::schema())
->icon('iconoir-plus-circle')
But not working.. am I missing something? Is this possible to be able to tell the form on this action to use a different model? Thanks
3 replies
FFilament
Created by julianwayu on 6/28/2024 in #❓┊help
Hidden Action and action modal not opening. But if remove hidden the modal works
If i have a table and in the table i have actions that are hidden/visible based on some criteria. and the action is supposed to open a modal with a form, it's not opening the modal. I can see the request to the server to "open" modal but the modal does not open. If I remove the 'hidden" or 'visible' methods from the action, then the modal opens without a problem. This code does NOT open modal
Tables\Actions\Action::make('uploadCover')
->icon('iconoir-media-image-plus')
->hidden(fn ($record): bool => !$record->canAction($user, 'release_upload_cover'))
->form([
Forms\Components\FileUpload::make('cover')
->label('Cover')
->image()
->directory('covers')
])
->action(function (array $data, Model $record): void {
dd($data, $record);
})
Tables\Actions\Action::make('uploadCover')
->icon('iconoir-media-image-plus')
->hidden(fn ($record): bool => !$record->canAction($user, 'release_upload_cover'))
->form([
Forms\Components\FileUpload::make('cover')
->label('Cover')
->image()
->directory('covers')
])
->action(function (array $data, Model $record): void {
dd($data, $record);
})
This code WORKS as expected
Tables\Actions\Action::make('uploadCover')
->icon('iconoir-media-image-plus')
->form([
Forms\Components\FileUpload::make('cover')
->label('Cover')
->image()
->directory('covers')
])
->action(function (array $data, Model $record): void {
dd($data, $record);
})
Tables\Actions\Action::make('uploadCover')
->icon('iconoir-media-image-plus')
->form([
Forms\Components\FileUpload::make('cover')
->label('Cover')
->image()
->directory('covers')
])
->action(function (array $data, Model $record): void {
dd($data, $record);
})
Please help. Thanks
38 replies
FFilament
Created by julianwayu on 4/3/2024 in #❓┊help
How to make table groups have a specific order?
For example, I'm grouping by status but i would like the groups to be listed in a specific order. Not asc/desc but maybe by a weight? So lets say I have ASC: Completed, Draft, Pending, I want to show the groups in this order: Draft, Pending, Completed any way to do this?
2 replies
FFilament
Created by julianwayu on 12/20/2023 in #❓┊help
Persist Tenant
Was trying to see if there is a way to persist the current tenant in the database on "tenant switch". Similar to how Laravel Jetstream does. Jetstream stores the current team to the Users table as 'current_team_id' and would be nice to do that,
3 replies