Vp
Vp
FFilament
Created by Vp on 6/17/2024 in #❓┊help
section footer action to submit the section schema
How can I make section footer Action to submit the section schema form? docs links: https://filamentphp.com/docs/3.x/forms/layout/section#adding-actions-to-the-sections-footer I create a page filament-page and added custom multiple form (https://filamentphp.com/docs/3.x/forms/adding-a-form-to-a-livewire-component#using-multiple-forms) I want to submit the section form by using the section footer action, how can I achieve this? Code:
return $form
->schema([
Forms\Components\Section::make('test')
->aside()
->schema([
Forms\Components\TextInput::make('title'),
])
->footerActions([
Forms\Components\Actions\Action::make('save') // how can I make this action to submit section schema
->action(function (array $data) {
dd($data);
}),
]),
])
return $form
->schema([
Forms\Components\Section::make('test')
->aside()
->schema([
Forms\Components\TextInput::make('title'),
])
->footerActions([
Forms\Components\Actions\Action::make('save') // how can I make this action to submit section schema
->action(function (array $data) {
dd($data);
}),
]),
])
8 replies
FFilament
Created by Vp on 5/28/2024 in #❓┊help
export notification message doesn't change base on locale
No description
38 replies
FFilament
Created by Vp on 5/6/2024 in #❓┊help
How to eager load relationship inside infolist repeatable entry
I've enable prevent lazy loading like this in providers Model::preventLazyLoading(! $this->app->isProduction()); I create a relationship manager and I display the data in infolist. but when it comes to repeatable entry like below example, I always got this error Attempted to lazy load [customer] on model [App\Models\Reply] but lazy loading is disabled.
protected static string $relationship = 'comments';

public function infolist(Infolist $infolist): Infolist
{
return $infolist
->schema([
// ...

Infolists\Components\RepeatableEntry::make('replies')
->schema([
Infolists\Components\TextEntry::make('customer.name'),
]),
]);
}

// Comment model
public function replies(): HasMany
{
return $this->hasMany(Reply::class);
}

// Reply model
public function customer(): BelongsTo
{
return $this->belongsTo(Customer::class);
}
protected static string $relationship = 'comments';

public function infolist(Infolist $infolist): Infolist
{
return $infolist
->schema([
// ...

Infolists\Components\RepeatableEntry::make('replies')
->schema([
Infolists\Components\TextEntry::make('customer.name'),
]),
]);
}

// Comment model
public function replies(): HasMany
{
return $this->hasMany(Reply::class);
}

// Reply model
public function customer(): BelongsTo
{
return $this->belongsTo(Customer::class);
}
I can put protected $with = ['customer']; inside Model, but it's not a great solution IMO, so what should be the best way to eager load the relationship
26 replies
FFilament
Created by Vp on 4/8/2024 in #❓┊help
select 'default' not working in filter action/forms
I am trying to filter dashboard widget using filter action/forms, I provide months options and try to set default to current month. Below is how I did
FilterAction::make()
->form([
Forms\Components\Select::make('month')
->options([
1 => 'January',
2 => 'February',
3 => 'March',
4 => 'April',
5 => 'May',
...
])
->default(now()->month)
->selectablePlaceholder(false),
]),
FilterAction::make()
->form([
Forms\Components\Select::make('month')
->options([
1 => 'January',
2 => 'February',
3 => 'March',
4 => 'April',
5 => 'May',
...
])
->default(now()->month)
->selectablePlaceholder(false),
]),
When page refresh, the select options always pointing to first item only instead of default
13 replies
FFilament
Created by Vp on 4/8/2024 in #❓┊help
Auto scroll to selected navigation not implement in spa() mode?
Today I am just checking out spa() mode and everything seems working so far in resources, pages etc., but notice small issue, I am not sure whether this is intentional or not. As we can see from video, If I am not using spa then the active sidebar is showing in the center (auto scroll to selected navigation) but If I enable spa then it's showing from top (from Dashboard). Before (last month) I used this code to auto scroll to selected navigation, but I am not sure in which version this is included in core so I removed from my providers and it's working fine still, but not in spa()
// now I completely removed this from providers
Filament::registerRenderHook(
'panels::scripts.before',
fn () => new HtmlString(html: "
<script>
document.addEventListener('DOMContentLoaded', function(){
setTimeout(() => {
const activeSidebarItem = document.querySelector('.fi-sidebar-item-active');
const sidebarWrapper = document.querySelector('.fi-sidebar-nav');

if (activeSidebarItem && sidebarWrapper) {
sidebarWrapper.style.scrollBehavior = 'smooth';

sidebarWrapper.scrollTo(0, activeSidebarItem.offsetTop - 450);
}
}, 300)
});
</script>
"));
// now I completely removed this from providers
Filament::registerRenderHook(
'panels::scripts.before',
fn () => new HtmlString(html: "
<script>
document.addEventListener('DOMContentLoaded', function(){
setTimeout(() => {
const activeSidebarItem = document.querySelector('.fi-sidebar-item-active');
const sidebarWrapper = document.querySelector('.fi-sidebar-nav');

if (activeSidebarItem && sidebarWrapper) {
sidebarWrapper.style.scrollBehavior = 'smooth';

sidebarWrapper.scrollTo(0, activeSidebarItem.offsetTop - 450);
}
}, 300)
});
</script>
"));
My questions is "Is this intentional or bug?"
2 replies
FFilament
Created by Vp on 3/27/2024 in #❓┊help
textinput prefix with select dropdown
No description
7 replies
FFilament
Created by Vp on 3/8/2024 in #❓┊help
Manually fill simple repeater data value on edit
I'm storing repeater value to another table, each value will be based on languages. On create it's working fine (storing).. but on edit the repeater value cannot display.. what can I do to fill simple repeater value on edit
// form
foreach (Language::all() as $language) {
$fields[] = Forms\Components\Tabs\Tab::make('translations.'.$language->id)
->label($language->name)
->schema([
Forms\Components\TextInput::make('translations.'.$language->id.'.plan_name')
->required(),

Forms\Components\Repeater::make('translations.'.$language->id.'.features')
->simple(
Forms\Components\TextInput::make('translations.'.$language->id.'.features')
->required(),
)
]);
}

// create (working fine)
Actions\CreateAction::make()
->after(function (Model $record, array $data) {
foreach ($data['translations'] as $key => $value) {
$record->translations()->create([
'language_id' => $key,
'plan_name' => $value['plan_name'],
'features' => $value['features'],
]);
}
}),

// edit (it cannot fill repeater data)
Tables\Actions\EditAction::make()
->mutateRecordDataUsing(function (Model $record, array $data): array {
foreach ($record?->translations as $translation) {
$data['translations'][$translation->language_id]['plan_name'] = $translation->plan_name;
$data['translations'][$translation->language_id]['features'] = $translation->features;
}

// dd($data);

return $data;
}),

// relationship
public function translations(): HasMany
{
return $this->hasMany(ProductTranslation::class);
}
// form
foreach (Language::all() as $language) {
$fields[] = Forms\Components\Tabs\Tab::make('translations.'.$language->id)
->label($language->name)
->schema([
Forms\Components\TextInput::make('translations.'.$language->id.'.plan_name')
->required(),

Forms\Components\Repeater::make('translations.'.$language->id.'.features')
->simple(
Forms\Components\TextInput::make('translations.'.$language->id.'.features')
->required(),
)
]);
}

// create (working fine)
Actions\CreateAction::make()
->after(function (Model $record, array $data) {
foreach ($data['translations'] as $key => $value) {
$record->translations()->create([
'language_id' => $key,
'plan_name' => $value['plan_name'],
'features' => $value['features'],
]);
}
}),

// edit (it cannot fill repeater data)
Tables\Actions\EditAction::make()
->mutateRecordDataUsing(function (Model $record, array $data): array {
foreach ($record?->translations as $translation) {
$data['translations'][$translation->language_id]['plan_name'] = $translation->plan_name;
$data['translations'][$translation->language_id]['features'] = $translation->features;
}

// dd($data);

return $data;
}),

// relationship
public function translations(): HasMany
{
return $this->hasMany(ProductTranslation::class);
}
On edit, total rows are correctly populated without value.. and this approach correctly filled text input Plan name
6 replies
FFilament
Created by Vp on 2/13/2024 in #❓┊help
validation message in rules not working
I have this below code, but my custom validation message cannot trigger, it showing default laravel validation.
Forms\Components\FileUpload::make('cover')
->required()
->rules([
'dimensions:ratio=2/1',
])
->validationMessages([
'dimensions' => 'Error !!!',
])
Forms\Components\FileUpload::make('cover')
->required()
->rules([
'dimensions:ratio=2/1',
])
->validationMessages([
'dimensions' => 'Error !!!',
])
Can we override rules validation message as well using ->validationMessages()?
4 replies
FFilament
Created by Vp on 1/26/2024 in #❓┊help
How to change SelectFilter indicator
No description
4 replies
FFilament
Created by Vp on 1/22/2024 in #❓┊help
How to change multiple file upload grid column
No description
5 replies
FFilament
Created by Vp on 1/17/2024 in #❓┊help
How to give custom permission to sub-navigation relation manager
I create resource sub-navigation using https://filamentphp.com/docs/3.x/panels/resources/getting-started#resource-sub-navigation and also follow the demo https://demo.filamentphp.com/blog/posts/1 but I want to show/hide navigation button based on permission, I'm using Shield.
public static function getRecordSubNavigation(Page $page): array
{
return $page->generateNavigationItems([
Pages\ViewList::class,
Pages\EditList::class,
Pages\ManageResult::class, // relation-manager (how can i apply `can('viewResult')` permission here
]);
}
public static function getRecordSubNavigation(Page $page): array
{
return $page->generateNavigationItems([
Pages\ViewList::class,
Pages\EditList::class,
Pages\ManageResult::class, // relation-manager (how can i apply `can('viewResult')` permission here
]);
}
If I just put inside table action then I can do like this and it's working
Tables\Actions\Action::make('result')
->url(function (Model $record) {
return ListResource::getUrl('result', [
'record' => $record->id,
]);
})
->visible(fn () => self::can('viewResult')), // this is working
Tables\Actions\Action::make('result')
->url(function (Model $record) {
return ListResource::getUrl('result', [
'record' => $record->id,
]);
})
->visible(fn () => self::can('viewResult')), // this is working
How can I apply (show/hide) result relation manager based on custom permission?
4 replies
FFilament
Created by Vp on 1/13/2024 in #❓┊help
Access form data inside beforeFormValidated()
I have country code field, I want to save +012 (notice plus sign) in database. but on input, I don't want user to insert "+" so I use mutateFormDataUsing() to append before save, but however this doesn't work with ->unique() validation, it always try to save to DB. My codes:
Forms\Components\TextInput::make('country_code')
->prefix('+')
->unique(ignoreRecord: true),

Actions\CreateAction::make()
->beforeFormValidated(function () {
// how to access form data here
})
Forms\Components\TextInput::make('country_code')
->prefix('+')
->unique(ignoreRecord: true),

Actions\CreateAction::make()
->beforeFormValidated(function () {
// how to access form data here
})
EDIT I notice that mutateFormDataUsing() run after validation, so how can I access form data inside ->beforeFormValidated()?
3 replies
FFilament
Created by Vp on 1/11/2024 in #❓┊help
sub navigation in custom page
No description
5 replies
FFilament
Created by Vp on 1/11/2024 in #❓┊help
Question about Action
I notice that when we close a modal, there is two update server call.. I am not sure if this a bug or not, so asking about explanation or "in general" why? This make a little slow and sometimes it cannot open the next action when we click fast
3 replies
FFilament
Created by Vp on 1/11/2024 in #❓┊help
Weird error in compile theme
No description
8 replies
FFilament
Created by Vp on 1/3/2024 in #❓┊help
halt table toggle column
How can I halt (not updating DB) toggle column?
Tables\Columns\ToggleColumn::make('recommend')
->beforeStateUpdated(function () {
$recommendCount = Model::where('recommend', true)->count();

if ($recommendCount >= 15) {
// @todo(notification)
return false; // not working
}
}),
Tables\Columns\ToggleColumn::make('recommend')
->beforeStateUpdated(function () {
$recommendCount = Model::where('recommend', true)->count();

if ($recommendCount >= 15) {
// @todo(notification)
return false; // not working
}
}),
In my case, if recommend count is gte = 15, I want to hold that event and shows notification and hold update process, but it still updating, how can I make it "not to update table" Thanks in advance
7 replies
FFilament
Created by Vp on 12/28/2023 in #❓┊help
Passing parameters to extracted filter (for DRY)
I have date (from - to) filter and I used all of my application, but I want to extract and follow DRY If I try like below then I got this error unresolveable (Flare link https://flareapp.io/share/xPQZOxk7)
public static function filter($column) // working if remove $column
{
return Tables\Filters\Filter::make($column) // working if I put 'created_at'
->form([
Forms\Components\DatePicker::make('from')
->native(false),

Forms\Components\DatePicker::make('to')
->native(false),
])
->query(function (Builder $query, array $data, string $column): Builder { // working if remove $column
return $query
->when(
$data['from'],
fn (Builder $query, $date, $column): Builder => $query->whereDate($column, '>=', $date), // working if i remove $column from fn() and use 'created_at' in whereDate
)
->when(
$data['to'],
fn (Builder $query, $date, $column): Builder => $query->whereDate($column, '<=', $date),
);
});
}

// Call from resources like this
\App\Filament\Common\Filter::filter('created_at') // or updated_at, working without passing data
public static function filter($column) // working if remove $column
{
return Tables\Filters\Filter::make($column) // working if I put 'created_at'
->form([
Forms\Components\DatePicker::make('from')
->native(false),

Forms\Components\DatePicker::make('to')
->native(false),
])
->query(function (Builder $query, array $data, string $column): Builder { // working if remove $column
return $query
->when(
$data['from'],
fn (Builder $query, $date, $column): Builder => $query->whereDate($column, '>=', $date), // working if i remove $column from fn() and use 'created_at' in whereDate
)
->when(
$data['to'],
fn (Builder $query, $date, $column): Builder => $query->whereDate($column, '<=', $date),
);
});
}

// Call from resources like this
\App\Filament\Common\Filter::filter('created_at') // or updated_at, working without passing data
How can I pass dynamic data in my custom filter? If I use created_at instead of variable then it's working fine
5 replies
FFilament
Created by Vp on 12/25/2023 in #❓┊help
hint action random data in form input
I am trying to create a reset password, the new password will auto generated on modal pop-up, when they click "refresh" it will change the password string (random). What I did: Auto generated password is done but I am stuck on refresh (hint action) My code:
Tables\Actions\Action::make('resetPassword')
->requiresConfirmation()
->fillForm([
'password' => Str::random(12),
])
->form([
Forms\Components\TextInput::make('password')
->required()
->hintAction(
Action::make('refresh')
->hiddenLabel()
->icon('heroicon-o-arrow-path')
->action(function (array $data) {
dd($data); // how to make random 'password' again?
})
)
])
Tables\Actions\Action::make('resetPassword')
->requiresConfirmation()
->fillForm([
'password' => Str::random(12),
])
->form([
Forms\Components\TextInput::make('password')
->required()
->hintAction(
Action::make('refresh')
->hiddenLabel()
->icon('heroicon-o-arrow-path')
->action(function (array $data) {
dd($data); // how to make random 'password' again?
})
)
])
How can I change the password value after clicking refresh (hintAction)
4 replies
FFilament
Created by Vp on 12/22/2023 in #❓┊help
Toggle column with confirmation
Can we show confirmation modal when table toggle is changed? I want the confirmation to pop-up when I try to toggle column and based on that it should reflect the status What I tried: I thought this link https://filamentphp.com/docs/3.x/tables/columns/toggle#lifecycle-hooks should do the trick, but I am stucking here My code:
use Filament\Actions\Action;

Tables\Columns\ToggleColumn::make('is_verified')
->beforeStateUpdated(function ($record, $state) {
Action::make('confirm')
->requiresConfirmation();

dd($record);
}),
use Filament\Actions\Action;

Tables\Columns\ToggleColumn::make('is_verified')
->beforeStateUpdated(function ($record, $state) {
Action::make('confirm')
->requiresConfirmation();

dd($record);
}),
It always shows dd() value instead of action, thanks in advance
5 replies
FFilament
Created by Vp on 12/20/2023 in #❓┊help
500 error on localhost when visit admin panel
My admin panels is working fine before, but now when I visit admin panel it shows "Page is not working, host is currently unable to handle this request. HTTP ERROR 500" and maximum execution time error display on terminal also.. All others pages/url are working fine except admin panel. What should be the case? I tried: 1. composer update 2. clear all cache optimize:clear 3. filament upgrade 4. remove vendor, composer lock and composer i but nothing works When I install new laravel + new filament then this issue is not happening... What should be my case to fix? thanks in advance
4 replies