kennyhorna
kennyhorna
FFilament
Created by kennyhorna on 9/20/2024 in #❓┊help
Conditionally displaying delete action in a Repeater based on row
Hello, My model has a "active" field that should enable/disable the deletion of the element in the repeater. I know that there's a ->deleteAction(fn ($action) => ...) function, but I haven't been able to figure out how to inject the current row. I tried with $state but the whole repeater array is included instead. Is there a way to accomplish this?
11 replies
FFilament
Created by kennyhorna on 8/26/2024 in #❓┊help
Problem when saving a record in a form that contains a table (custom filament Livewire component)
Morning 👋🏽 I have the following case. Case I have the SaleTrackingResource. This resource has a 1-M relationship with SaleDay, that in turn, has a 1-M relationship with SaleDayEntry. - SaleTrackingResource 1-m SaleDay 1-m SaleDayEntry Since I need to display the SaleDayEntry objects in a table in the SaleTrackingResource, I created a custom Livewire component, ListSaleDayEntries. I extended the Livewire\Component class and it implements the HasForms& HasTable interfaces. It looks like this [Image 1]. How it's rendered: In the SaleTrackingResource, I have a section that renders the SaleDays dynamically. Each day will have a tab, and within that tab is that I make a new instance of the custom Livewire component I mentioned earlier, the ListSaleDayEntries. This is the relevant code:
Section::make('saleDays')
->label('Tours')
->visibleOn('edit')
->columns(1)
->collapsible()
->headerActions([
Action::make('create-day')
->label('Agregar Día')
->url(fn(?SalesTracking $record) => CreateTourSaleDay::getUrl([
'sales_tracking_id' => $record?->id,
]))
])
->schema([
Tabs::make('tourSaleDays')
->hiddenLabel()
->hidden(fn(?SalesTracking $record) => ! $record?->tourSaleDays()->exists())
->schema(
fn(?SalesTracking $record) => $record
?->tourSaleDays
->map(fn(TourSaleDay $day) => Tabs\Tab::make($day->name)
->schema([
Livewire::make('entries')
->id($day->id . '-' . $day->name)
->component('list-tour-sale-day-entries')
->data(['record' => $day]),
]))
->toArray() ?? [],
)
]),
Section::make('saleDays')
->label('Tours')
->visibleOn('edit')
->columns(1)
->collapsible()
->headerActions([
Action::make('create-day')
->label('Agregar Día')
->url(fn(?SalesTracking $record) => CreateTourSaleDay::getUrl([
'sales_tracking_id' => $record?->id,
]))
])
->schema([
Tabs::make('tourSaleDays')
->hiddenLabel()
->hidden(fn(?SalesTracking $record) => ! $record?->tourSaleDays()->exists())
->schema(
fn(?SalesTracking $record) => $record
?->tourSaleDays
->map(fn(TourSaleDay $day) => Tabs\Tab::make($day->name)
->schema([
Livewire::make('entries')
->id($day->id . '-' . $day->name)
->component('list-tour-sale-day-entries')
->data(['record' => $day]),
]))
->toArray() ?? [],
)
]),
Problem I will put the problem in reply below
6 replies
FFilament
Created by kennyhorna on 8/11/2024 in #❓┊help
How to re-render/refresh the parent form after a new entry of a RelationManager has been created?
Hello, I want to refresh the main form/resource (or the whole page if possible) after a new entry has been created through a RelationManager of the resource. This is my setup: - Resource: PriceListResource - RelationManager: SectionsRelationManager - Relationship name: sections I have tried this so far: 1. RelationsManager/SectionsRelationManager.php:
// ...
->headerActions([
Tables\Actions\CreateAction::make()
->after(fn () => $this->dispatch('section-added')),
])
// ...
// ...
->headerActions([
Tables\Actions\CreateAction::make()
->after(fn () => $this->dispatch('section-added')),
])
// ...
Then in the edit resource page I listen to that event: 2. PriceListResource/Pages/EditPriceList.php
use Livewire\Attributes\On;

// ...

#[On('section-added')]
public function refreshForm(): void
{
$this->refreshFormData(['sections']);
}
use Livewire\Attributes\On;

// ...

#[On('section-added')]
public function refreshForm(): void
{
$this->refreshFormData(['sections']);
}
The event/listener works (I added a dd() in there and I can see it being triggered) but I can make it refresh the relationship. I guess because sections is not an attribute per-se. The reason why I need this is because within the form I have a TableRepeater that is built dynamically based on this relation. Then, how could I achieve the refresh/re-render?
18 replies
FFilament
Created by kennyhorna on 7/29/2024 in #❓┊help
Customize "create :resource" button label
No description
19 replies
FFilament
Created by kennyhorna on 7/17/2024 in #❓┊help
Repeater item id
Hello, Is there a way to access the item id (or uuid) within the element? For example, to have it available in the >formatStateUsing(callback) Thanks in advance.
5 replies
FFilament
Created by kennyhorna on 7/9/2024 in #❓┊help
Required field
No description
5 replies
FFilament
Created by kennyhorna on 8/21/2023 in #❓┊help
Set record in ViewRecord page
Hi, I'm creating a custom panel for a customer role. So I would like to limit the view/edit actions for this customer to only be able manage his/hers business. So my idea is to create BusinessResource and then use the ViewBusiness to display the data using an infolist, so then I can add a new entry in the nav pointing to the view page directly. My problem right now is that I cannot set the record in the view page. So this is my Business::getPages():
return [
'view' => Pages\ViewBusiness::route('/my-business'),
];
return [
'view' => Pages\ViewBusiness::route('/my-business'),
];
I've tried to set the record using this 3 methods but so far no luck:
public function getRecord(): Model
{
return auth()->user()->business;
}

protected function resolveRecord(int|string|null $key): Model
{
return auth()->user()->business;
}

public function setRecord(Model|int|string|null $record): void
{
$this->record = auth()->user()->business;
}
public function getRecord(): Model
{
return auth()->user()->business;
}

protected function resolveRecord(int|string|null $key): Model
{
return auth()->user()->business;
}

public function setRecord(Model|int|string|null $record): void
{
$this->record = auth()->user()->business;
}
But I'm still getting:
Unable to resolve dependency [Parameter #0 [ <required> string|int $record ]] in class Filament\Resources\Pages\ViewRecord
Unable to resolve dependency [Parameter #0 [ <required> string|int $record ]] in class Filament\Resources\Pages\ViewRecord
How could I achieve this? Or maybe some guidance in case there's an easier approach. Thanks in advance 🙂
9 replies
FFilament
Created by kennyhorna on 8/12/2023 in #❓┊help
How to set default values (to persist) on repeater
Hi, I'm building a table to specify the opening hours of businesses. So, I want to populate a repeater with weekdays. Currently I'm doing this:
->default([
[
'day' => 'monday',
'start' => null,
'end' => null,
],
[ // ...
->default([
[
'day' => 'monday',
'start' => null,
'end' => null,
],
[ // ...
Which it display them fine, but when I want to persist the data -> the values of the 'day' key (that is being handled on a Select field) are not being passed (remain null). Only when I manually clic on the select and change it -> they are included in the request. How to include the values by default? Thanks in advance.
2 replies
FFilament
Created by kennyhorna on 8/7/2023 in #❓┊help
Change relantion manager tab title
6 replies
FFilament
Created by kennyhorna on 8/3/2023 in #❓┊help
Problem loading livewire.js on v3
Hi! I can't find a way to make to make it to work. I still see error 500. I have tried to add the following to my site config (local, I'm using Valet)
location ^~ /filament {
try_files $uri $uri/ /index.php?$query_string;
}
location ^~ /filament {
try_files $uri $uri/ /index.php?$query_string;
}
Also, in Livewire v3 there's no asset_url option in the config but now this https://livewire.laravel.com/docs/installation#customizing-the-asset-url Ps: I installed v3 beta (filament + livewire) from scratch. Have you experiencie this? Thanks in advance.
5 replies