Horizons
Horizons
FFilament
Created by Horizons on 12/13/2023 in #❓┊help
Best practice to inject additional attributes into my Laravel model to persist in state
Hello, I have an Application model (paper form converted to digital) where I retreive extra attributes from an external table and append them to my model. Currently, after a preform an action on my Infolist page the extra attributes are lost on the page refresh when the action is called. So I'm retreiving them again with afterActionCalled(). This seems very inefficient as the same query is being called multiple times on same page. What is the best practice to append these extra attributes to my Infolist state?
2 replies
FFilament
Created by Horizons on 11/17/2023 in #❓┊help
Persisting Model Data between Form Updates
I'm using the mount method to load extra data attributes to my model to present on the form in a View component. When I trigger a form input to become visible the model refreshes and I lose my extra data. Is there a way to stop the model from being refreshed or is there another method I could use to re-inject my data attributes?
public function mount(): void
{
$this->record = new Model();
$this->record->fillPersonalInfo();

$this->form->fill($this->record->toArray());
}

public function form(Form $form): Form
{
return $form->schema([
Section::make('')->schema([
\Filament\Forms\Components\View::make('personal')
->view('application/fiPersonalInfo', ['eops' => $this->record])
]),
...
])->statePath('data')->model($this->record);
}
public function mount(): void
{
$this->record = new Model();
$this->record->fillPersonalInfo();

$this->form->fill($this->record->toArray());
}

public function form(Form $form): Form
{
return $form->schema([
Section::make('')->schema([
\Filament\Forms\Components\View::make('personal')
->view('application/fiPersonalInfo', ['eops' => $this->record])
]),
...
])->statePath('data')->model($this->record);
}
2 replies
FFilament
Created by Horizons on 11/9/2023 in #❓┊help
Panel Issues
I am running into some issues working with a panel. The help functions route() and auth() are giving me errors. The route() helper states the named route doesn't exist when it does. And the auth() helper is stating a user provider isn't defined. Are these helper methods not useable within the Filament environment?
return $panel
...
->navigationItems([
NavigationItem::make('Home')
->icon('heroicon-o-home')
->url(route('home')
->sort(1),
NavigationItem::make('Admin Panel')
->url('/admin')
->sort(2)
->visible(auth()->user()->hasRoles('Super Admin')),
])
...
return $panel
...
->navigationItems([
NavigationItem::make('Home')
->icon('heroicon-o-home')
->url(route('home')
->sort(1),
NavigationItem::make('Admin Panel')
->url('/admin')
->sort(2)
->visible(auth()->user()->hasRoles('Super Admin')),
])
...
5 replies
FFilament
Created by Horizons on 10/24/2023 in #❓┊help
How to modify a model before form fill?
Hello. I have a laravel form I'm trying to convert into Filament. Before loading the create page I would reach out to an external database for info about the user. Is this possible to do with a filament resource?
public function fillApplicationPersonalInfo(): static
{
$this->id = $this->user->id ?? auth()->user()->id;
$results = $this->getExternalUserPersonalInfo();
$this->setData($results);

return $this;
}
public function fillApplicationPersonalInfo(): static
{
$this->id = $this->user->id ?? auth()->user()->id;
$results = $this->getExternalUserPersonalInfo();
$this->setData($results);

return $this;
}
This function sets attributes on my Application model so I have access to them on the create page.
3 replies