Diogo Pinto
Diogo Pinto
FFilament
Created by Diogo Pinto on 3/25/2024 in #❓┊help
Import action - fill relationship hasone
Hey all, I'm trying to import a CSV that has a price relationship (hasOne). This is how I'm trying to do it:
ImportColumn::make('price')
->fillRecordUsing(function (Product $record, string $state): void {
$record->price_id = $record->price()->create([
'price' => $state,
'type' => 'one_time',
])->id;
})
->integer(),
ImportColumn::make('price')
->fillRecordUsing(function (Product $record, string $state): void {
$record->price_id = $record->price()->create([
'price' => $state,
'type' => 'one_time',
])->id;
})
->integer(),
Thing is, obviously, the $record->price can't be created because the record hasn't been assigned an ID yet. How can I approach this? Is it even possible with the Import action?
2 replies
FFilament
Created by Diogo Pinto on 3/23/2024 in #❓┊help
modifyQueryUsing based on request - action resets query
Hey all, Use case: - In the /view it gets all categories that don't have parent ids - When you click on a record it takes you to route /{record}/view - In /{record}/view it fetches all subcategories where parent_id = {record} Problem: - In /{record}/view when I click on a Table action, the query resets and the action doesn't perform. Here's the code:
public static function table(Table $table): Table
{
return $table
//other code
->recordAction('view', Pages\ListProductCategories::route('/{record}'))
->actions([
Tables\Actions\ActionGroup::make([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
])
->modifyQueryUsing(fn (Builder $query): Builder =>
$query->when(request()->route('record'), function ($query) {
return $query->where('parent_id', request()->route('record'));
}, function ($query) {
return $query->where('parent_id', null);
}));
}

public static function getPages(): array
{
return [
'index' => Pages\ListProductCategories::route('/'),
'view' => Pages\ListProductCategories::route('/{record}/view'),
];
}
public static function table(Table $table): Table
{
return $table
//other code
->recordAction('view', Pages\ListProductCategories::route('/{record}'))
->actions([
Tables\Actions\ActionGroup::make([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
])
->modifyQueryUsing(fn (Builder $query): Builder =>
$query->when(request()->route('record'), function ($query) {
return $query->where('parent_id', request()->route('record'));
}, function ($query) {
return $query->where('parent_id', null);
}));
}

public static function getPages(): array
{
return [
'index' => Pages\ListProductCategories::route('/'),
'view' => Pages\ListProductCategories::route('/{record}/view'),
];
}
I'm wondering if I'm doing anything wrong or approaching the wrong way. Thanks!
8 replies
FFilament
Created by Diogo Pinto on 3/19/2024 in #❓┊help
Adding relationship manager to livewire
Hello all, Is there a painless way to add a Relationship Manager to a custom livewire component? Use cases: - A edit profile page with an address (belongstomany) relationship - user can attach and detach addresses Thanks!
6 replies
FFilament
Created by Diogo Pinto on 12/15/2023 in #❓┊help
Blade pagination component malfunction
No description
3 replies
FFilament
Created by Diogo Pinto on 9/22/2023 in #❓┊help
Action shows view with nested actions?
Hey guys, how are you? How would you approach creating an action that is a livewire component by itself? Meaning, that when you click it renders a dynamic view with actions nested? I've used:
->modalContentFooter(fn ($record) => view(
'filament.actions.media-browser',
['documents' => $record->getDocuments()],
)),
->modalContentFooter(fn ($record) => view(
'filament.actions.media-browser',
['documents' => $record->getDocuments()],
)),
this returns an array, and in the blade file I user a foreach... but I want to be able to click an array item and when I click it, it renders a modal with something. Thank you so much!
8 replies
FFilament
Created by Diogo Pinto on 9/18/2023 in #❓┊help
Spatie Media Library File upload - for each file, create model record
No description
9 replies
FFilament
Created by Diogo Pinto on 9/6/2023 in #❓┊help
SelectFilter relationship field
Hello all, I have a users table, with a relation (HasOne) user_meta table. So the relationship is: $user->meta->professional_category That returns the professional category of the user. So, why doesn't this filter work?
Tables\Filters\SelectFilter::make('professional_category')
->options(ProfessionalCategory::class) //Enum Class
->relationship('meta', 'professional_category')
->preload(),
Tables\Filters\SelectFilter::make('professional_category')
->options(ProfessionalCategory::class) //Enum Class
->relationship('meta', 'professional_category')
->preload(),
The output:
Filament\Forms\Components\Select::getRelationship(): Return value must be of type Illuminate\Database\Eloquent\Relations\BelongsTo|Illuminate\Database\Eloquent\Relations\BelongsToMany|Znck\Eloquent\Relations\BelongsToThrough|null, Illuminate\Database\Eloquent\Relations\HasOne returned
Filament\Forms\Components\Select::getRelationship(): Return value must be of type Illuminate\Database\Eloquent\Relations\BelongsTo|Illuminate\Database\Eloquent\Relations\BelongsToMany|Znck\Eloquent\Relations\BelongsToThrough|null, Illuminate\Database\Eloquent\Relations\HasOne returned
I don't know what I'm doing wrong. Must I run the query directly?
6 replies
FFilament
Created by Diogo Pinto on 9/4/2023 in #❓┊help
Textinput suffix icon color
Hello all, I'm wondering if there is any way to add a color to the suffix icon on my input. Use case: An action validates a country code, if the country code is true it affixes the valid icon:
->action(function (Forms\Components\TextInput $component, $state) {
$iban = new ValidateIban($state);
if ($iban->checkIfValid()) {
$component->suffixIcon('heroicon-m-check');
}
})
->action(function (Forms\Components\TextInput $component, $state) {
$iban = new ValidateIban($state);
if ($iban->checkIfValid()) {
$component->suffixIcon('heroicon-m-check');
}
})
` I'm wondering if there is a way to add a color to the suffixIcon. Thank you!
2 replies
FFilament
Created by Diogo Pinto on 8/31/2023 in #❓┊help
User Set Password after registering User in the panel
Hello all, I'm building a user resource that enables Admins to register users manually. When an action is toggled to enable the login, the action triggers the Email Verification process:
app()->bind(
\Illuminate\Auth\Listeners\SendEmailVerificationNotification::class,
\Filament\Listeners\Auth\SendEmailVerificationNotification::class,
);
// Trigger the email verification process
event(new Registered($this->record));
app()->bind(
\Illuminate\Auth\Listeners\SendEmailVerificationNotification::class,
\Filament\Listeners\Auth\SendEmailVerificationNotification::class,
);
// Trigger the email verification process
event(new Registered($this->record));
Now what I would like to achieve is to enable the user to set a password when he clicks the verify email. What would be your approach? I don't think fillament has anything under the hood ready for this after looking at the docs, but I may be wrong! Thank you!
15 replies
FFilament
Created by Diogo Pinto on 8/29/2023 in #❓┊help
Hide header actions on edit page
Hello! I'm looking to customize the "delete" button on the edit page, to only show conditionally on my records. Is there a way to achieve this? Thanks!
4 replies
FFilament
Created by Diogo Pinto on 8/25/2023 in #❓┊help
Decimal separator to comma instead of dot
Hey all, In my country we use comma as a decimal separator instead of a dot. So I would like to ask: how to change de price display/input to get and set with a comma as a decimal separator? Doing this on a resource level with masks for input transformation seem like an overkill. Thanks!
9 replies
FFilament
Created by Diogo Pinto on 8/24/2023 in #❓┊help
Model with different layout based on category
Hello all, I would like your help on how to achieve this logically taking in account good coding principles, indexing and performance issues. Imagine the following: - A model of "Books" - Books can have different "Categories" - When creating a Book: -- If category is Fiction shows fields A, B and C -- If category is Non-Fiction shows fields D, E, F My questions: - How should I store that data? -- Should I have all those fields in the database and leave empty depending on category -- Or should i just have a "meta" column and store it as JSON? - How would I show each field set based on category selected? Thank you. I'm new to filament and before getting hands on I'm trying to write all the logic behind this. Thanks!
5 replies