Custom Component Within Resource.

I've created a new resource with basic add, edit, and delete functionality. My question is: Is it possible to include a custom component within the resource, such as a custom form section or field?
14 Replies
toeknee
toeknee7d ago
@Nicole absolutely, just add them in the resources form.
Nicole
NicoleOP7d ago
You mean that if I have this resource, I can simple insert any custom created component with custom function there?
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255)
->live(onBlur: true)
->afterStateUpdated(fn (string $operation, $state, Forms\Set $set) => $operation === 'create' ? $set('slug', Str::slug($state)) : null),

Forms\Components\TextInput::make('slug')
->disabled()
->dehydrated()
->required()
->maxLength(255)
->unique(Category::class, 'slug', ignoreRecord: true),

Forms\Components\MarkdownEditor::make('description')
->columnSpan('full'),

Forms\Components\Toggle::make('is_visible')
->label('Visible to customers.')
->default(true),
]);
}
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255)
->live(onBlur: true)
->afterStateUpdated(fn (string $operation, $state, Forms\Set $set) => $operation === 'create' ? $set('slug', Str::slug($state)) : null),

Forms\Components\TextInput::make('slug')
->disabled()
->dehydrated()
->required()
->maxLength(255)
->unique(Category::class, 'slug', ignoreRecord: true),

Forms\Components\MarkdownEditor::make('description')
->columnSpan('full'),

Forms\Components\Toggle::make('is_visible')
->label('Visible to customers.')
->default(true),
]);
}
toeknee
toeknee7d ago
Within the schema yes you can also use the Livewire component to render livewire components too. You can also insert widgets for edit/view/create pages too. It's all in the docs
Nicole
NicoleOP7d ago
Is it possible to add a button to the middle of the create form that, when clicked, sends a request to an external API and fills other form fields based on the response?
Nicole
NicoleOP7d ago
The idea is like this
No description
toeknee
toeknee7d ago
Yes it is possible, that's an action button really. Let me see if I can find a guide
Nicole
NicoleOP7d ago
This is what I found so maybe you have other guides https://laraveldaily.com/post/filament-add-custom-action-button-inside-form
toeknee
toeknee7d ago
Yes that's the one I was looking for
Nicole
NicoleOP7d ago
Oh, got it. Thanks! Maybe you have idea for this one as well? https://discord.com/channels/883083792112300104/1364866419036262453 I just need a map to show the location in a map so lightweight map will work. Based on latitude and longitude
toeknee
toeknee7d ago
Just use any map field, and then set it as ->disabled() so it just shows the location.
Nicole
NicoleOP7d ago
Is there a map field? I can't find it in docs
toeknee
toeknee7d ago
Filament
Plugins - Filament
Community made packages for Filament projects, which give you access to awesome new features.
toeknee
toeknee7d ago
Plenty above
Nicole
NicoleOP7d ago
Thank you so much toeknee

Did you find this page helpful?