mark.cameron
mark.cameron
FFilament
Created by ChesterS on 8/12/2024 in #❓┊help
Access form data in modal action
Would need some way of accessing the parent form, as I don't believe it's available there in the nested action inside extraModalFooterActions
9 replies
FFilament
Created by ChesterS on 8/12/2024 in #❓┊help
Access form data in modal action
@Matthew Doesn't work for me
Typed property Filament\Forms\Components\Component::$container must not be accessed before initialization
9 replies
FFilament
Created by ChesterS on 8/12/2024 in #❓┊help
Access form data in modal action
It's ugly, and and probably not the way to go, but I found the form data here:
->extraModalFooterActions([
Action::make('bar')
->action(function ($record, Component $livewire) {
$data = $livewire->mountedTableActionsData[0];
}),
])
->extraModalFooterActions([
Action::make('bar')
->action(function ($record, Component $livewire) {
$data = $livewire->mountedTableActionsData[0];
}),
])
mountedTableActionsData is an array, so you might need to choose a different key than 0 depending on your setup.
9 replies
FFilament
Created by mark.cameron on 2/26/2024 in #❓┊help
Cluster with EditResource form, and other custom pages that interact with a specific resource
@Joao Gomes Thanks for this!
8 replies
FFilament
Created by qcol on 7/31/2023 in #❓┊help
summarize and custom model attribute
I'm not sure if they example custom sum above was for Filament v2.x or not, but it wasn't working properly on my v3.x, and was taking all models, not just those limited to the table I was displaying. Here's a different version based off the above example which I used for formatting the sums of Attributes for a money column, but that can easily be changed according to your needs.
<?php

namespace App\Filament\Components\Tables;

use Exception;
use Filament\Tables\Columns\Summarizers\Summarizer;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\Schema;

class MoneySumAttribute extends Summarizer
{
protected function setUp(): void
{
parent::setUp();

$this->numeric()
->money(
config('filament-money-field.default_currency'),
100,
config('filament-money-field.default_locale')
);
}

/**
* @return int | float | array<string, array<string, int>> | null
*/
public function summarize(Builder $query, string $attribute): int | float | array | null
{
$column = $this->getColumn();
$isField = Schema::hasColumn($this->getQuery()->getModel(), $column->getName());

if ($isField) {
throw new Exception("The [{$column->getName()}] column must be an Attribute.");
}

$eloquentQuery = $this->getQuery()->getModel()->setQuery($query);
return $eloquentQuery->get()->pluck($attribute)->sum();
}

public function getDefaultLabel(): ?string
{
return __('filament-tables::table.summary.summarizers.sum.label');
}
}
<?php

namespace App\Filament\Components\Tables;

use Exception;
use Filament\Tables\Columns\Summarizers\Summarizer;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\Schema;

class MoneySumAttribute extends Summarizer
{
protected function setUp(): void
{
parent::setUp();

$this->numeric()
->money(
config('filament-money-field.default_currency'),
100,
config('filament-money-field.default_locale')
);
}

/**
* @return int | float | array<string, array<string, int>> | null
*/
public function summarize(Builder $query, string $attribute): int | float | array | null
{
$column = $this->getColumn();
$isField = Schema::hasColumn($this->getQuery()->getModel(), $column->getName());

if ($isField) {
throw new Exception("The [{$column->getName()}] column must be an Attribute.");
}

$eloquentQuery = $this->getQuery()->getModel()->setQuery($query);
return $eloquentQuery->get()->pluck($attribute)->sum();
}

public function getDefaultLabel(): ?string
{
return __('filament-tables::table.summary.summarizers.sum.label');
}
}
9 replies
FFilament
Created by Vp on 5/6/2024 in #❓┊help
How to eager load relationship inside infolist repeatable entry
For future visitors: You can do something like this to eager load the relationship on the "View" page for your resource by overriding the mount() method, might be other ways or cleaner ways, but I couldn't see any other way to interact with the query:
<?php

...

class ViewNews extends ViewRecord
{
protected static string $resource = NewsResource::class;

#[\Override]
public function mount(int | string $record): void
{
parent::mount($record);

$this->record->load('contactables.contact', 'contactables.category');
}

...
}
<?php

...

class ViewNews extends ViewRecord
{
protected static string $resource = NewsResource::class;

#[\Override]
public function mount(int | string $record): void
{
parent::mount($record);

$this->record->load('contactables.contact', 'contactables.category');
}

...
}
26 replies
FFilament
Created by Vp on 5/6/2024 in #❓┊help
How to eager load relationship inside infolist repeatable entry
Thanks for your help!
26 replies
FFilament
Created by Vp on 5/6/2024 in #❓┊help
How to eager load relationship inside infolist repeatable entry
Ok thanks I'll have a look there
26 replies
FFilament
Created by Vp on 5/6/2024 in #❓┊help
How to eager load relationship inside infolist repeatable entry
Ok that might explain it, as I'm on a new page the relationship query isn't called from the $table...
26 replies
FFilament
Created by Vp on 5/6/2024 in #❓┊help
How to eager load relationship inside infolist repeatable entry
As in, is yours a simple resource? And when you click on view, it display the resource in a Modal, and not on it's own page?
26 replies
FFilament
Created by Vp on 5/6/2024 in #❓┊help
How to eager load relationship inside infolist repeatable entry
ahh, is yours in a modal ?
26 replies
FFilament
Created by Vp on 5/6/2024 in #❓┊help
How to eager load relationship inside infolist repeatable entry
My relation is the contactables one and using the with('contact')
26 replies
FFilament
Created by Vp on 5/6/2024 in #❓┊help
How to eager load relationship inside infolist repeatable entry
This is the code for the table() and infolist() methods on the resource
26 replies
FFilament
Created by Vp on 5/6/2024 in #❓┊help
How to eager load relationship inside infolist repeatable entry
It's all vendor stuff
26 replies
FFilament
Created by Vp on 5/6/2024 in #❓┊help
How to eager load relationship inside infolist repeatable entry
Ok thanks for the example, but I still get the but lazy loading is disabled message for the relationship that I define in the modifyQueryUsing(). Not sure what I am missing... But even debugging the modifyQueryUsing(), and I'm not passing through it when on the Infolist...
26 replies
FFilament
Created by Vp on 5/6/2024 in #❓┊help
How to eager load relationship inside infolist repeatable entry
@Vp Where did you put the ->modifyQueryUsing() ? I get a method doesn't exist on the Infolist when I try it like this:
return $infolist
->modifyQueryUsing(...)
->schema([
return $infolist
->modifyQueryUsing(...)
->schema([
It only appears to work on $table, but that has no effect on ths Infolist display when viewing the model... Thanks for your help!
26 replies
FFilament
Created by Andrius on 1/23/2024 in #❓┊help
Access resource record/model in custom component registered via registerRenderHook
@Andrius I was running into this issue today too, and I tried putting the registerRenderHook in a Middleware instead of a Service provider. I guess you could probably still do this through a service provider, but it wouldn't be as clean... Then in the Custom Middleware handle() method I run my checks for where to add the RenderHook (kind of like using the scopes: method parameter),
$model = Model::find($request->route('record'));

FilamentView::registerRenderHook(
PanelsRenderHook::PAGE_END,
fn (): string => Blade::render('@livewire(\'my-component\', [\'record\' => $model])', ['model' => $model]),
);
$model = Model::find($request->route('record'));

FilamentView::registerRenderHook(
PanelsRenderHook::PAGE_END,
fn (): string => Blade::render('@livewire(\'my-component\', [\'record\' => $model])', ['model' => $model]),
);
Then in my Livewire component I have a class property which gets populated with the parameter in the @livewire(...) string from the blade component
public Model $record;
public Model $record;
4 replies
FFilament
Created by mark.cameron on 2/26/2024 in #❓┊help
Cluster with EditResource form, and other custom pages that interact with a specific resource
@Jon Mason Unfortunately I still have not figured this out. Yourself?
8 replies
FFilament
Created by code eater on 12/16/2023 in #❓┊help
How do i access raw file in action modal
@code eater Could you share how you managed it, please?
5 replies
FFilament
Created by Kleis on 8/31/2023 in #❓┊help
Hide widget on dashboard
@Kleis Ever figure this one out? Running into this issue as well... Can't move it out of app/Filament/Widgets or comment ->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets') in AdminPanelProvider...
11 replies