Finn
Finn
FFilament
Created by Finn on 6/12/2024 in #❓┊help
Where does this modal come from in my Builder?
No description
6 replies
FFilament
Created by Finn on 4/20/2024 in #❓┊help
Best way to create a virtual/fake input?
I have the following fields:
Select::make('type_fake')
->label('Collectie type')
->options([
'main' => 'Hoofd collectie',
'has_parent' => 'Sub collectie (valt onder andere collectie)',
])
->native(false)
->default('main')
->live()
->required(),

Select::make('parent_id')
->label('Sub collectie van')
->options(ShopCollection::query()->whereNull('parent_id')->pluck('name', 'id'))
->searchable()
->preload()
->native(false)
->required()
->visible(fn (Get $get) => $get('type_fake') === 'has_parent'),
Select::make('type_fake')
->label('Collectie type')
->options([
'main' => 'Hoofd collectie',
'has_parent' => 'Sub collectie (valt onder andere collectie)',
])
->native(false)
->default('main')
->live()
->required(),

Select::make('parent_id')
->label('Sub collectie van')
->options(ShopCollection::query()->whereNull('parent_id')->pluck('name', 'id'))
->searchable()
->preload()
->native(false)
->required()
->visible(fn (Get $get) => $get('type_fake') === 'has_parent'),
The parent_id only comes up when has_parent has been selected as a value in the type_fake select. So the first select should not be inserted/filled into the Model. Is there a way to define a field is a fake/virtual field which should not be saved in the eloquent model? So I can avoid the SQLSTATE[42S22]: Column not found: 1054 Unknown column 'type_fake' in 'field list' error.
3 replies
FFilament
Created by Finn on 4/14/2024 in #❓┊help
Let Filament decrypt database value in TextInput
I got a TextInput field in a form in Filament which is a encrypted value in the database. I have the Laravel cast encrypted on it in my model, but Filament does not seem to decrypt the value if you edit 🤔
21 replies
FFilament
Created by Finn on 3/24/2024 in #❓┊help
Empty tenant dropdown
No description
1 replies
FFilament
Created by Finn on 9/20/2023 in #❓┊help
Disabled field through $set function not updating state
I used the Filament documentation (https://filamentphp.com/docs/3.x/forms/advanced#generating-a-slug-from-a-title) to automatically generate a slug based on a text field. Like this:
TextInput::make('name')
->label('Naam')
->required()
->live()
->afterStateUpdated(function (Get $get, Set $set, ?string $old, ?string $state): void {
if (($get('slug') ?? '') !== Str::slug($old)) {
return;
}

$set('slug', Str::slug($state));
}),

TextInput::make('slug')
->prefix('https://test.nl/categorie/')
->suffix('.nl')
->disabled(),
TextInput::make('name')
->label('Naam')
->required()
->live()
->afterStateUpdated(function (Get $get, Set $set, ?string $old, ?string $state): void {
if (($get('slug') ?? '') !== Str::slug($old)) {
return;
}

$set('slug', Str::slug($state));
}),

TextInput::make('slug')
->prefix('https://test.nl/categorie/')
->suffix('.nl')
->disabled(),
As you can see I am disabling the slug TextInput, because I dont want users to be able to modify it as it automatically does that. When I click on save I get an error that the slug column cannot be inserted in my database because the value is null. But it does have a value think If I remove the ->disabled() from the slug TextInput it does save fine.
4 replies
FFilament
Created by Finn on 9/15/2023 in #❓┊help
Section of fields that I can re-use over multiple resources/custom pages
I want to make a custom field like SEOData::make() which contains a few fields that go to a relationship of that model. But I dont know if a custom field is the way to go, because I dont want to make a custom blade etc. It basically needs to be a reusable set of fields. Because multiple resources have a relationship to a model called PageMeta.php, and I want to implement those fields out of that database table into multiple resources/custom pages. I can just copy and paste those fields over and over again, but then if I need to change it, I need to do it on multiple places which of course isn't what you want. What's the best way to do this?
6 replies
FFilament
Created by Finn on 8/16/2023 in #❓┊help
One record resource
I am currently creating a website for a customer which should be able to edit content on the website. Now I had the idea to make everything managable through Filament (it will act as a CMS like Wordpress basically) because it's such easy to use and great looking. My original thought was: I will create a Database table called "home" which just has 1 record in it with columns such as: title, description, contact_button_text, header_image etc. which will be managable through Filament. Once the home page loads it will get the first record out of the database and send that to the page to load the text and images etc from those variables out of the database. Now to make it directly available without a "table view" within Filament when clicking on the resource in the menu, my thought was to make a custom navigation item which directly points to: project.test/home-page/1/edit this will edit record 1 because it only will have one record of course. But sounds kinda hacky to me, which doesn't matter, but maybe someone else achieved making something like this and has better idea's on making site content managable through Filament? I would love to hear that! I also know Filament's purpose isn't to be a CMS, but I think it would be perfect for this project.
21 replies
FFilament
Created by Finn on 3/23/2023 in #❓┊help
Modify relationship data before inserting/creating
So I do have a resource, with a form with multiple text inputs. In that form I made a fieldset that links to a relation
Forms\Components\Fieldset::make(self::$relationName)
->relationship(self::$relationName)
->label('Pagina informatie')
->schema([
Forms\Components\TextInput::make('meta_title')
->label('Meta title')
->required(),
Forms\Components\TextInput::make('meta_description')
->label('Meta description')
->required(),
])
Forms\Components\Fieldset::make(self::$relationName)
->relationship(self::$relationName)
->label('Pagina informatie')
->schema([
Forms\Components\TextInput::make('meta_title')
->label('Meta title')
->required(),
Forms\Components\TextInput::make('meta_description')
->label('Meta description')
->required(),
])
As you can see, in there I have 2 inputs in there. Now when I click on create in Filament, I want to modify the data from the text input. Normally I would modify the data in the app\Filament\Resources\MyResource\Pages\CreateMyResourcePage.php using the mutateFormDataBeforeCreate(array $data) method. But in the $data of the mutateFormDataBeforeCreate method, I do not have access to the relationship properties <a:aPES_Think:493353113332219924> So how would I modify it?
3 replies
FFilament
Created by Finn on 3/5/2023 in #❓┊help
Access relationship data in mutateFormDataBeforeCreate
I have created a Repeater that goes into another model 'invoice_rows' like this: Forms\Components\Repeater::make('invoice_rows')->label('Factuur regels')->relationship('row') with the ->relationship('row') function. But in my resource Create file (CreateAdminInvoices.php) I use protected function mutateFormDataBeforeCreate(array $data) and I want to access the form data of the relationship there as well, but that's not included in the $data variable. How do I make that accessible there as well?
7 replies