nathan269_
nathan269_
FFilament
Created by nathan269_ on 2/4/2025 in #❓┊help
$this->form->fill clears whole form
Hi folks, I have an action setup that when I click it, it will fetch data from an api. I don't want the data that has been fetched to update automatically. I use the following:
$this->form->fill([
'page_views' => $Response['pageviews'],
'unique_visits' => $Response['visitors'],
'avg_time_on_page' => $Response['visit_duration'],
'top_pages' => $this->topPages,
]);
$this->form->fill([
'page_views' => $Response['pageviews'],
'unique_visits' => $Response['visitors'],
'avg_time_on_page' => $Response['visit_duration'],
'top_pages' => $this->topPages,
]);
the above code is contained within the function that is called by my action/button. I have other input fields throughout the page that already have data outwith the page_views, unique_visits, avg_time_on_page and top_pages. When I click the action button and it successfully fills in the data fetched into the specified input fields, however, it clears all other input fields throughout the page that haven't been specified in the form->fill. How do i prevent this from happening? I also tried the following that was suggested online but had no luck:
$this->fillForm();
$this->fillForm();
5 replies
FFilament
Created by nathan269_ on 9/3/2024 in #❓┊help
How To Call Service To Retrieve Data Within Table Widget?
Hi folks, how can i retrieve data from a service I have setup, from within the table widget? I previously used the ->query method because I just reference data from within my database, however, i no longer save the data anymore. This is my code:
private PlausibleAnalyticsService $plausibleAnalyticsService;

public function __construct()
{
$this->plausibleAnalyticsService = new PlausibleAnalyticsService();
}

protected function getData(): array
{
return $this->plausibleAnalyticsService->fetchTopPages();
}

public function table(Tables\Table $table): Tables\Table
{
return $table
// set data from fetchTopPages() method
->columns([
TextColumn::make('page')
->label('Page')
->getStateUsing(fn ($record) => $record['page']),
TextColumn::make('visitors')
->label('Visitors')
->getStateUsing(fn ($record) => number_format($record['visitors'])),
TextColumn::make('pageviews')
->label('Page Views')
->getStateUsing(fn ($record) => number_format($record['pageviews'])),
]);
}
private PlausibleAnalyticsService $plausibleAnalyticsService;

public function __construct()
{
$this->plausibleAnalyticsService = new PlausibleAnalyticsService();
}

protected function getData(): array
{
return $this->plausibleAnalyticsService->fetchTopPages();
}

public function table(Tables\Table $table): Tables\Table
{
return $table
// set data from fetchTopPages() method
->columns([
TextColumn::make('page')
->label('Page')
->getStateUsing(fn ($record) => $record['page']),
TextColumn::make('visitors')
->label('Visitors')
->getStateUsing(fn ($record) => number_format($record['visitors'])),
TextColumn::make('pageviews')
->label('Page Views')
->getStateUsing(fn ($record) => number_format($record['pageviews'])),
]);
}
2 replies
FFilament
Created by nathan269_ on 6/21/2024 in #❓┊help
What is the best/easiest way to overwrite a resource within a package?
I'm using the following 2 packages and would like to edit both resources:
"z3d0x/filament-logger": "^0.7.1"
"bezhansalleh/filament-exceptions": "^2.1",
"z3d0x/filament-logger": "^0.7.1"
"bezhansalleh/filament-exceptions": "^2.1",
This is the path for each: vendor/z3d0x/filament-logger/src/Resources/ActivityResource.php vendor/bezhansalleh/filament-exceptions/src/Resources/ExceptionResource.php
3 replies
FFilament
Created by nathan269_ on 2/23/2024 in #❓┊help
Conditional Pageblock Dependent On Resource
Is there a way to only display a pageblock in a particular resource? I have this for example:
public static function getBlockSchema(): Block
{
return Block::make('exit_popup')
->label('Exit Popup')
->when('resource', 'ComponentResource')
->schema([
TextInput::make('title')
->label('Title')
->required(),

TextArea::make('intro')
->label('Intro')
->required(),

TextInput::make('submission_message')
->label('Submission Message')
->required(),

TextInput::make('button_label')
->label('Button Label')
->required(),
]);
}
public static function getBlockSchema(): Block
{
return Block::make('exit_popup')
->label('Exit Popup')
->when('resource', 'ComponentResource')
->schema([
TextInput::make('title')
->label('Title')
->required(),

TextArea::make('intro')
->label('Intro')
->required(),

TextInput::make('submission_message')
->label('Submission Message')
->required(),

TextInput::make('button_label')
->label('Button Label')
->required(),
]);
}
I only want this pageblock to be visible within the ComponentResource. Is this possible?
17 replies
FFilament
Created by nathan269_ on 1/9/2024 in #❓┊help
Light/Dark Mode Logo
Hi I have the following for my logo:
<div x-data="{ isdark: localStorage.getItem('theme') === 'dark' }">
<span x-on:theme-changed.window="isdark = !isdark"></span>
<img src="{{ asset('/images/logo-alt.svg') }}" alt="Logo" class="h-10 w-auto" x-show="!isdark">
<img src="{{ asset('/images/vtm-logo-alt.svg') }}" alt="Dark Logo" class="h-10 w-auto" x-show="isdark">
</div>
<div x-data="{ isdark: localStorage.getItem('theme') === 'dark' }">
<span x-on:theme-changed.window="isdark = !isdark"></span>
<img src="{{ asset('/images/logo-alt.svg') }}" alt="Logo" class="h-10 w-auto" x-show="!isdark">
<img src="{{ asset('/images/vtm-logo-alt.svg') }}" alt="Dark Logo" class="h-10 w-auto" x-show="isdark">
</div>
although this works while logged in and switching between light and dark mode, it doesn't work when I sign out from the admin and I'm on the sign in page (that displays our logo). For example, if when signed in i was in dark mode and the light version of our logo is displayed and then I sign out and have a dark themed sign in form, the logo is no longer a light version and switches back to the dark version of the logo.
5 replies
FFilament
Created by nathan269_ on 12/13/2023 in #❓┊help
Filament Curator (srcset not working)
Hi Folks, I'm trying to figure out how to properly set multiple srcset/sizes for the following image:
<x-curator-glider
class="absolute inset-0 -z-10 h-full w-full object-cover"
:media="3"
:srcset="['2000w','768w','480w']"
sizes="(max-width: 2000px) 2000px, (max-width: 768px) 768px, (max-width: 480px) 480px"
format="webp"
quality="80"
force="true"
alt=""
/>
<x-curator-glider
class="absolute inset-0 -z-10 h-full w-full object-cover"
:media="3"
:srcset="['2000w','768w','480w']"
sizes="(max-width: 2000px) 2000px, (max-width: 768px) 768px, (max-width: 480px) 480px"
format="webp"
quality="80"
force="true"
alt=""
/>
I want a different size of image to be displayed dependent on what the current screen size is. With what I have set, no matter what screen size I have, it always sets to the largest option (2000) like so: "http://website.test/curator/media/36ea4b52-f699-4491-b97c-e1a25e75efe0.jpg?fm=webp&h=1125&q=80&w=2000&s=edc3024d7bc5c7cc2a74cd46b56b1b09" Have I set this wrong?
9 replies
FFilament
Created by nathan269_ on 10/27/2023 in #❓┊help
How do I Determine What Action is Called?
Apologies if this is covered in the filament docs, however, i couldn't find anything based on this issue. I have the following in my AuthorResource: ``` Forms\Components\TextInput::make('email') ->label('Email') ->required() ->email() ->columnSpan(['sm' => 2]) ->unique(modifyRuleUsing: function (Unique $rule) { return $rule->where('is_published', 1); }), and this in the EditAuthor: Action::make('save') ->action('save') ->label(fn (EditRecord $livewire) => $livewire->getRecord()->isPublished() ? __('filament-panels::resources/pages/edit-record.form.actions.save.label') : 'Publish') ->icon(fn (EditRecord $livewire) => $livewire->getRecord()->isPublished() ? 'heroicon-o-check-circle' : 'heroicon-o-eye'), how can i check that if the action "save" is called, then I should apply the ->unique rule that I have set, and if anything other than action "save" don't apply the unique rule.
3 replies
FFilament
Created by nathan269_ on 10/19/2023 in #❓┊help
How to Position Package Resources?
Hi everyone, how would i position the resource for a package I have here within my AdminPanelProvider?

->plugins([
CuratorPlugin::make(),
EnvironmentIndicatorPlugin::make()
->showBadge(false)
->showBorder(true)
->color(fn () => match (app()->environment()) {
'production' => Color::hex('#dc2626'),
'staging' => Color::hex('#ea580c'),
default => Color::hex('#2563eb'),
}),
FilamentNavigation::make(),
FilamentUsersPlugin::make(),
FilamentSpatieRolesPermissionsPlugin::make()
]);

->plugins([
CuratorPlugin::make(),
EnvironmentIndicatorPlugin::make()
->showBadge(false)
->showBorder(true)
->color(fn () => match (app()->environment()) {
'production' => Color::hex('#dc2626'),
'staging' => Color::hex('#ea580c'),
default => Color::hex('#2563eb'),
}),
FilamentNavigation::make(),
FilamentUsersPlugin::make(),
FilamentSpatieRolesPermissionsPlugin::make()
]);
I would like to change the position of the FilamentSpatieRolesPermissionsPlugin resource by doing something similar to this if possible:
FilamentSpatieRolesPermissionsPlugin::make()
->position(3)
FilamentSpatieRolesPermissionsPlugin::make()
->position(3)
I know you can go directly into resources and just do the following:
protected static ?int $navigationSort = 3;
protected static ?int $navigationSort = 3;
but I wasn't sure if there is an alternative way it can be done in within AdminPanelProvider.
7 replies