Anik
Anik
Explore posts from servers
FFilament
Created by Anik on 5/21/2024 in #❓┊help
resource in multiple panels
Hi, I am trying to reuse same model resource in different panels and display a slight different array of pages according to user. In the resource getPages() the filament currentpanel and auth()->user() are not available. what am i doing wrong?
public static function getPages(): array
{
dd(Filament::getCurrentPanel());
if (Filament::auth()->user() instanceof Admin) {
return [
'index' => Pages\ListBusinesses::route('/'),
'view' => Pages\ViewProfile::route('/{record}'),
'edit' => Pages\EditProfile::route('/{record}/edit'),
'viewKit' => Pages\ViewBusinessKit::route('/{record}/view-kit'),
'editKit' => Pages\EditBusinessKit::route('/{record}/edit-kit'),
'calender' => Pages\ViewCalender::route('/{record}/calender'),
];
}
}
public static function getPages(): array
{
dd(Filament::getCurrentPanel());
if (Filament::auth()->user() instanceof Admin) {
return [
'index' => Pages\ListBusinesses::route('/'),
'view' => Pages\ViewProfile::route('/{record}'),
'edit' => Pages\EditProfile::route('/{record}/edit'),
'viewKit' => Pages\ViewBusinessKit::route('/{record}/view-kit'),
'editKit' => Pages\EditBusinessKit::route('/{record}/edit-kit'),
'calender' => Pages\ViewCalender::route('/{record}/calender'),
];
}
}
Edit: I have kept the resources seperate and the pages common. Then in the pages, i am passing the correct resource after checking auth. this seems to work. what would be the optimum way? It would be less code if filament() would work inside getPages()
/**
* @return class-string
*/
public static function getResource(): string
{
if (filament()->auth()->user() instanceof Business) {
return LocationBusinessResource::class;
}
return BusinessResource::class;
}
/**
* @return class-string
*/
public static function getResource(): string
{
if (filament()->auth()->user() instanceof Business) {
return LocationBusinessResource::class;
}
return BusinessResource::class;
}
3 replies
NNuxt
Created by Anik on 5/4/2024 in #❓・help
nitropack error nuxtjs/sitemap
Hi, I am getting this error when installing the lastest nuxtjs/seo or nuxtjs/sitemap. Kindly help.
ERROR Error while requiring module D:/Github/JetPax-Production/node_modules/@nuxtjs/sitemap/dist/module.mjs: Error: Cannot find module 'nitropack' 1:43:07 am
Require stack:
- D:\Github\JetPax-Production\node_modules\@nuxtjs\sitemap\dist\module.mjs
ERROR Error while requiring module D:/Github/JetPax-Production/node_modules/@nuxtjs/sitemap/dist/module.mjs: Error: Cannot find module 'nitropack' 1:43:07 am
Require stack:
- D:\Github\JetPax-Production\node_modules\@nuxtjs\sitemap\dist\module.mjs
I have tried deleting node_module, package.json and reinstalling
2 replies
FFilament
Created by Anik on 4/13/2024 in #❓┊help
search placeholder update table
Hi, can the search placeholder for a table be updated to custom text?
3 replies
FFilament
Created by Anik on 3/16/2024 in #❓┊help
navigationitems override
Hello, I want to modify the url() in the navigationItem for a page class. right now they are set to static and cannot be overridden in a ListRecord class. I am trying to get Nested resource from this tutorial. https://laraveldaily.com/post/filament-v3-nested-resources-trait-pages The list page works as in the tutorial but when I use it with getRecordSubNavigation, it gives this error. https://flareapp.io/share/LPdK90Qm Kindly help. 😢
public static function getRecordSubNavigation(Page $page): array
{
return $page->generateNavigationItems([
// error from navigationItem::url() on being included here
])
}
public static function getRecordSubNavigation(Page $page): array
{
return $page->generateNavigationItems([
// error from navigationItem::url() on being included here
])
}
trying to override NavigationItem gives the error https://flareapp.io/share/Vme190qm
public static function getNavigationItems(array $urlParameters = []): array

{

return [

NavigationItem::make(static::getNavigationLabel())

->group(static::getNavigationGroup())

->parentItem(static::getNavigationParentItem())

->icon(static::getNavigationIcon())

->activeIcon(static::getActiveNavigationIcon())

// ->isActiveWhen(fn (): bool => request()->routeIs(static::getRouteName()))

->sort(static::getNavigationSort())

->badge(static::getNavigationBadge(), color: static::getNavigationBadgeColor())

->url(fn (): string => EventsResource::getUrl('bookings.index', ['parent' => $this->parent])),

];
}
public static function getNavigationItems(array $urlParameters = []): array

{

return [

NavigationItem::make(static::getNavigationLabel())

->group(static::getNavigationGroup())

->parentItem(static::getNavigationParentItem())

->icon(static::getNavigationIcon())

->activeIcon(static::getActiveNavigationIcon())

// ->isActiveWhen(fn (): bool => request()->routeIs(static::getRouteName()))

->sort(static::getNavigationSort())

->badge(static::getNavigationBadge(), color: static::getNavigationBadgeColor())

->url(fn (): string => EventsResource::getUrl('bookings.index', ['parent' => $this->parent])),

];
}
3 replies
FFilament
Created by Anik on 3/5/2024 in #❓┊help
navigation item disabled
Hi, can I disable clicking of navigation item based on a condition? similar to visible but it would be a locked state, not hidden
15 replies
FFilament
Created by Anik on 2/25/2024 in #❓┊help
disable form when media is uploaded
Hi, I want to disable form using $form->disabled() and also next button on wizard when a media is being uploaded. I have tried extra attributes on the button, but it isnt working
->nextAction(
fn (Action $action) => $action->label('Next')->extraAttributes([':disabled' => 'isUploadingFile']),
),
->nextAction(
fn (Action $action) => $action->label('Next')->extraAttributes([':disabled' => 'isUploadingFile']),
),
3 replies
FFilament
Created by Anik on 2/9/2024 in #❓┊help
badge in form placeholder
Hi, I am trying to display a xfilament badge inside a form placeholder. Any idea how can i achieve something like this?
Forms\Components\Placeholder::make('kyc_status')
->label('KYC Status')
->content(new HtmlString('<div><x-filament::badge>'
. $this->record->status->getLabel() . '</x-filament::badge>
<br/>' . $this->record->status_feedback . '</div>')),
Forms\Components\Placeholder::make('kyc_status')
->label('KYC Status')
->content(new HtmlString('<div><x-filament::badge>'
. $this->record->status->getLabel() . '</x-filament::badge>
<br/>' . $this->record->status_feedback . '</div>')),
5 replies
FFilament
Created by Anik on 2/9/2024 in #❓┊help
search highlight
Hi, is there any way to add matching text highlights to table search. It's way better for UX. We can see an example of it on this forum search as well.
16 replies
FFilament
Created by Anik on 1/28/2024 in #❓┊help
custom actions dont trigger on table
What I am trying to do: I am querying the data from a relationship and I need to update the pivot columns What I did: extended list record page used table query for modifying query to relationship->getQuery() My issue/the error: Custom Actions dont work when using relationship->getQuery() Code:
public function table(Table $table): Table
{
return $table
// action works but pivot data is not loaded ie cannot update invite_status
// ->query(fn (): Builder => Events::whereHas('artists', function ($query) {
// $query->where('artists.id', Filament::auth()->user()->id);
// }))
// pivot data is loaded but Action dont trigger modal
->query(fn (): Builder => Filament::auth()->user()->events()->getQuery())
->actions([
// works
ViewAction::make(),
// doesnt work
Action::make('approveAction')
->color('success')
->requiresConfirmation()
->visible(fn (Events $record): bool => $record->invite_status == ArtistInvite::SENT)
->action(fn (Events $record) => dd($record)),
Action::make('rejectAction')
->color('danger')
->requiresConfirmation()
->visible(fn (Events $record): bool => $record->invite_status == ArtistInvite::SENT)
->action(function (Events $record) {
$record->artists()->updateExistingPivot(Filament::auth()->user()->id, [
'invite_status' => ArtistInvite::REJECT
]);
})
])
->columns( // columns from the trait EventListSchema
$this->getEventTable()
)
->contentGrid([
'md' => 2,
]);
}
public function table(Table $table): Table
{
return $table
// action works but pivot data is not loaded ie cannot update invite_status
// ->query(fn (): Builder => Events::whereHas('artists', function ($query) {
// $query->where('artists.id', Filament::auth()->user()->id);
// }))
// pivot data is loaded but Action dont trigger modal
->query(fn (): Builder => Filament::auth()->user()->events()->getQuery())
->actions([
// works
ViewAction::make(),
// doesnt work
Action::make('approveAction')
->color('success')
->requiresConfirmation()
->visible(fn (Events $record): bool => $record->invite_status == ArtistInvite::SENT)
->action(fn (Events $record) => dd($record)),
Action::make('rejectAction')
->color('danger')
->requiresConfirmation()
->visible(fn (Events $record): bool => $record->invite_status == ArtistInvite::SENT)
->action(function (Events $record) {
$record->artists()->updateExistingPivot(Filament::auth()->user()->id, [
'invite_status' => ArtistInvite::REJECT
]);
})
])
->columns( // columns from the trait EventListSchema
$this->getEventTable()
)
->contentGrid([
'md' => 2,
]);
}
Kindly help.
1 replies
FFilament
Created by Anik on 1/27/2024 in #❓┊help
Livewire error after updating to v3.2.15
I am getting this error after updating to the latest version on an EditRecord page. Kindly help https://flareapp.io/share/x7KZkErP
5 replies
FFilament
Created by Anik on 1/2/2024 in #❓┊help
Display labels on table grid
Hi, is there a way to display labels on a table grid with component stacks. The table label are auto hidden on layout grid. It would be best if we had a way to toggle the display of labels on a table grid.
14 replies
FFilament
Created by Anik on 12/25/2023 in #❓┊help
repeater values for previous row
Hi, I have a Repeater for time slots where slots must not overlap and each slot's start must be after the end of the previous one. Kindly help me validate the code.
public function getAvailableSlots($day)
{
return TableRepeater::make('data.' . $day)->label(ucfirst($day))->columnSpan('full')->hideLabels()->emptyLabel('No available slots.')->schema([
Forms\Components\TimePicker::make('start')
->label('Start Time')
->seconds(false)
->lazy(),
Forms\Components\TimePicker::make('end')
->label('End Time')
->seconds(false)
->lazy()
->extraInputAttributes(function (Get $get) {
return [
'min' => Carbon::parse($get('start'))->addHour()->format('H:i')
];
}),
Forms\Components\TextInput::make('rate')
->label('Rate'),
]);
}
public function getAvailableSlots($day)
{
return TableRepeater::make('data.' . $day)->label(ucfirst($day))->columnSpan('full')->hideLabels()->emptyLabel('No available slots.')->schema([
Forms\Components\TimePicker::make('start')
->label('Start Time')
->seconds(false)
->lazy(),
Forms\Components\TimePicker::make('end')
->label('End Time')
->seconds(false)
->lazy()
->extraInputAttributes(function (Get $get) {
return [
'min' => Carbon::parse($get('start'))->addHour()->format('H:i')
];
}),
Forms\Components\TextInput::make('rate')
->label('Rate'),
]);
}
I want to get the value of the previous index in the json array for validation
2 replies
FFilament
Created by Anik on 9/16/2023 in #❓┊help
Radio components
Hello, Is there any way to pass html values to the radio descriptions?
3 replies
FFilament
Created by Anik on 8/22/2023 in #❓┊help
same tailwind.config,js for all panels
can we use same tailwind config for all panels instead of using $panel->colors(), like the tailwind theme config in v2
3 replies
FFilament
Created by Anik on 8/5/2023 in #❓┊help
live() is not working on CreateRecord page but working in Resource page form method
3 replies
FFilament
Created by Anik on 8/4/2023 in #❓┊help
flex wrap is not applied on table contentGrid for many action buttons
3 replies
FFilament
Created by Anik on 7/28/2023 in #❓┊help
opening modal on action button programmatically
https://filamentphp.com/docs/2.x/tables/actions#modals Hi, is there any method to open to the button modal on page load/mounted
Action::make('newPromo')
->button()
->label('Add Promo')
->color('primary')
->mountUsing(fn (ComponentContainer $form) => $form->fill([
'affiliate_id' => $this->affiliate->id,
]))
->action(function ($data) {
$data = array_merge($data,['event_id' => $this->eventId]);
$eventPromo = EventPromo::query()->create($data);
$this->notify('success', $eventPromo->name.' Promo Created');
return redirect()->to(EventsResource::getUrl('promos',['record' => $this->eventId]));

})
->form($this->promoForm())
->modalHeading('Add Promo')
->modalActions([
ModalButtonAction::make('create')
->label('Create')
->submit('callMountedAction')
->color('primary'),

ModalButtonAction::make('cancel')
->label('Cancel')
->cancel()
->color('secondary'),
])
// ->extraAttributes(['isOpen' => true])

Action::make('newPromo')
->button()
->label('Add Promo')
->color('primary')
->mountUsing(fn (ComponentContainer $form) => $form->fill([
'affiliate_id' => $this->affiliate->id,
]))
->action(function ($data) {
$data = array_merge($data,['event_id' => $this->eventId]);
$eventPromo = EventPromo::query()->create($data);
$this->notify('success', $eventPromo->name.' Promo Created');
return redirect()->to(EventsResource::getUrl('promos',['record' => $this->eventId]));

})
->form($this->promoForm())
->modalHeading('Add Promo')
->modalActions([
ModalButtonAction::make('create')
->label('Create')
->submit('callMountedAction')
->color('primary'),

ModalButtonAction::make('cancel')
->label('Cancel')
->cancel()
->color('secondary'),
])
// ->extraAttributes(['isOpen' => true])

8 replies
FFilament
Created by Anik on 7/11/2023 in #❓┊help
Spatie translatable issue with Spatie Tags
Hi, the table switcher is not working correctly on Spatie tags list page, but working on view/edit page. Reproduction Repo https://github.com/krishzzi/filament_testing temp solution https://discord.com/channels/883083792112300104/914836965076135936/1079470356760383529
2 replies
FFilament
Created by Anik on 5/17/2023 in #❓┊help
multiple models with relationships with Wizard Steps
Hi, I am using a Wizard Step with a model on a custom page to create and edit the model. I am having issues with SpatieMediaUpload which doesn't save the relation the first time on create but works well on edit. Sample code below
in Mount
$this->kyc = is_null($existKycRecord) ? $this->user->kyc()->getModel() : $existKycRecord;

Step::make('kyc')->model($this->kyc)
->afterValidation(function (Closure $get) {
$kycForm = [
'type' => $get('user_type'),
'has_tax' => $get('has_tax'),
];
$this->saveKyc($kycForm);
}),

Save function
public function saveKyc($data)
{
$this->kyc = $this->kyc->updateOrCreate(['user_id' => $this->user->id], $data);

$this->form->model($this->kyc)->saveRelationships();

$this->notify('success', 'User KYC Saved successfully!');

}
in Mount
$this->kyc = is_null($existKycRecord) ? $this->user->kyc()->getModel() : $existKycRecord;

Step::make('kyc')->model($this->kyc)
->afterValidation(function (Closure $get) {
$kycForm = [
'type' => $get('user_type'),
'has_tax' => $get('has_tax'),
];
$this->saveKyc($kycForm);
}),

Save function
public function saveKyc($data)
{
$this->kyc = $this->kyc->updateOrCreate(['user_id' => $this->user->id], $data);

$this->form->model($this->kyc)->saveRelationships();

$this->notify('success', 'User KYC Saved successfully!');

}
The form isn't saved when saveKyc is run the first time (on wizard next) but the function saves the relationships if it's run a second time (going previous and next on the wizard). I am looking for a way to save a multi model form with attachments via SpatieMedia.
2 replies