tjodalv
tjodalv
FFilament
Created by Abel Cobreros on 2/19/2024 in #❓┊help
Issue with halt() on beforeSave and a repeater with relationship
I am having exactly the same issue. Problem is that Filament is saving the repeater relationship before beforeSave() hook is executed.
5 replies
FFilament
Created by tjodalv on 3/13/2024 in #❓┊help
ImportAction job is failing but there is no error message
No description
8 replies
FFilament
Created by tjodalv on 3/13/2024 in #❓┊help
ImportAction job is failing but there is no error message
This is my error log from laravel.log file
8 replies
FFilament
Created by tjodalv on 2/21/2024 in #❓┊help
Action inside modal is not working
Just to post an update how I solved this problem. The problem was my misuse of Filament actions. I've created new Livewire component in which created filament table, just like the documentation says. I've passed my invoice record to the livewire via property.
// app/Livewire/InvoicePaymentsTable.php
class InvoicePaymentsTable extends Component implements HasForms, HasTable
{
use InteractsWithTable;
use InteractsWithForms;

public Invoice $invoice;

public function table(Table $table): Table
{
return $table
->relationship(fn (): MorphMany => $this->invoice->payments())
->inverseRelationship('payable')
->paginated(false)
->columns([
TextColumn::make('payed_at')->dateTime('d.m.Y'),
TextColumn::make('amount'),
])
->actions([
DeleteAction::make()
]);
}

public function render()
{
return <<<'blade'
<div>{{ $this->table }}</div>
blade;
}
}
// app/Livewire/InvoicePaymentsTable.php
class InvoicePaymentsTable extends Component implements HasForms, HasTable
{
use InteractsWithTable;
use InteractsWithForms;

public Invoice $invoice;

public function table(Table $table): Table
{
return $table
->relationship(fn (): MorphMany => $this->invoice->payments())
->inverseRelationship('payable')
->paginated(false)
->columns([
TextColumn::make('payed_at')->dateTime('d.m.Y'),
TextColumn::make('amount'),
])
->actions([
DeleteAction::make()
]);
}

public function render()
{
return <<<'blade'
<div>{{ $this->table }}</div>
blade;
}
}
And in the modal content view I called the livewire component like this:
<!-- /resources/filament/modals/payments-list.blade.php -->
...
@if ($record->payments->count() > 0)
<livewire:invoice-payments-table :invoice="$record" />
@endif
<!-- /resources/filament/modals/payments-list.blade.php -->
...
@if ($record->payments->count() > 0)
<livewire:invoice-payments-table :invoice="$record" />
@endif
And finally Action that opens that modal:
\Filament\Tables\Actions\Action::make('openPayments')
->modalContent(function (Invoice $record) {
return view('filament.modals.payments-list', compact(
'record',
));
})
\Filament\Tables\Actions\Action::make('openPayments')
->modalContent(function (Invoice $record) {
return view('filament.modals.payments-list', compact(
'record',
));
})
12 replies
FFilament
Created by tjodalv on 2/21/2024 in #❓┊help
Action inside modal is not working
Hi Saade, thank you for your help. I've refactored my code like this:
->registerModalActions([
DeleteAction::make("removeInvoicePayment")
->hiddenLabel()
->size('sm')
->icon('heroicon-s-x-mark')
])
->modalContent(function ($record, $action) {
return view('filament.modals.payments-list', compact(
'record',
'action'
));
})
->registerModalActions([
DeleteAction::make("removeInvoicePayment")
->hiddenLabel()
->size('sm')
->icon('heroicon-s-x-mark')
])
->modalContent(function ($record, $action) {
return view('filament.modals.payments-list', compact(
'record',
'action'
));
})
And in the view:
@foreach($record->payments as $payment)
<tr>
<td class="px-3 py-3.5">{{ $payment->payed_at->format('d.m.Y') }}</td>
<td class="px-3 py-3.5">{{ $payment->amount }}</td>
<td class="px-3 py-3.5">{{ $action->getModalAction('removeInvoicePayment')->name("removeInvoicePayment{$payment->id}")->record($payment) }}</td>
</tr>
@endforeach
@foreach($record->payments as $payment)
<tr>
<td class="px-3 py-3.5">{{ $payment->payed_at->format('d.m.Y') }}</td>
<td class="px-3 py-3.5">{{ $payment->amount }}</td>
<td class="px-3 py-3.5">{{ $action->getModalAction('removeInvoicePayment')->name("removeInvoicePayment{$payment->id}")->record($payment) }}</td>
</tr>
@endforeach
In the view I am renaming the button so it has unique name and assign record to be payment. There is no error, but that delete button is still not working. The record is not deleted in the database when the button is clicked.
12 replies
FFilament
Created by tjodalv on 2/21/2024 in #❓┊help
Action inside modal is not working
As I am using remove payment button inside of the for loop I created a function that constuct DeleteAction button for every row like this, but still doesn't work:
->modalContent(function ($record) {
$removePaymentAction = static function ($model) {
return DeleteAction::make("removePayment{$model->id}")
->record($model)
->hiddenLabel()
->size('sm')
->icon('heroicon-s-x-mark');
};

return view('filament.modals.payments-list', compact(
'record',
'removePaymentAction'
));
})
->modalContent(function ($record) {
$removePaymentAction = static function ($model) {
return DeleteAction::make("removePayment{$model->id}")
->record($model)
->hiddenLabel()
->size('sm')
->icon('heroicon-s-x-mark');
};

return view('filament.modals.payments-list', compact(
'record',
'removePaymentAction'
));
})
And then in view my loop goes like this:
@foreach($record->payments as $payment)
<tr>
<td class="px-3 py-3.5">{{ $payment->payed_at->format('d.m.Y') }}</td>
<td class="px-3 py-3.5">{{ $payment->amount }}</td>
<td class="px-3 py-3.5">{{ $removePaymentAction($payment) }}</td>
</tr>
@endforeach
@foreach($record->payments as $payment)
<tr>
<td class="px-3 py-3.5">{{ $payment->payed_at->format('d.m.Y') }}</td>
<td class="px-3 py-3.5">{{ $payment->amount }}</td>
<td class="px-3 py-3.5">{{ $removePaymentAction($payment) }}</td>
</tr>
@endforeach
But that still doesn't work for some reason.
12 replies
FFilament
Created by tjodalv on 2/21/2024 in #❓┊help
Action inside modal is not working
I get black modal open across the whole page with no response. Just black modal
12 replies
FFilament
Created by tjodalv on 2/21/2024 in #❓┊help
Action inside modal is not working
There is no response at all
12 replies
FFilament
Created by tjodalv on 2/21/2024 in #❓┊help
Action inside modal is not working
No description
12 replies
FFilament
Created by Askancy on 1/29/2024 in #❓┊help
Modal in form Resource
The best candidate for what you are trying to achieve would be hint action. Basically on any field you can define hint action that can open the modal with instructions:
Textarea::make('your_field_name')
->prefix('My field')
->hintAction(
Action::make('shortcode_instructions')
->modalContent(view('filament.pages.actions.shortcode-instructions'))
)
Textarea::make('your_field_name')
->prefix('My field')
->hintAction(
Action::make('shortcode_instructions')
->modalContent(view('filament.pages.actions.shortcode-instructions'))
)
More on hint actions here: https://filamentphp.com/docs/3.x/forms/actions#passing-multiple-hint-actions-to-a-field
5 replies
FFilament
Created by tjodalv on 1/27/2024 in #❓┊help
ViewAction on resource's table listing page
I've manage to find the solution to my problem using mountUsing() method on an action by inspecting how ViewAction works in the Filament. This is my solution:
Tables\Actions\Action::make('view-linked-user')
->label('Show user')
->slideOver(true)
->mountUsing(function (Form $form, Estimate $record) {
$user = User::find($record->user_id);
$form->model($user);
$form->operation('view');
$form->disabled(true);
$form->fill($user->toArray());
})
->form(function (Estimate $record): array {
return [...UserForm::fields()];
});
Tables\Actions\Action::make('view-linked-user')
->label('Show user')
->slideOver(true)
->mountUsing(function (Form $form, Estimate $record) {
$user = User::find($record->user_id);
$form->model($user);
$form->operation('view');
$form->disabled(true);
$form->fill($user->toArray());
})
->form(function (Estimate $record): array {
return [...UserForm::fields()];
});
In my form() method I am calling my custom class UserForm that define fields for this action and for my UserResource class.
9 replies
FFilament
Created by tjodalv on 1/27/2024 in #❓┊help
ViewAction on resource's table listing page
I can use table's ViewAction to open User on the ListUsers.php page. I would like to open a modal to view user details on the ListEstimate.php page. The estimate is linked to a user.
9 replies
FFilament
Created by tjodalv on 1/27/2024 in #❓┊help
ViewAction on resource's table listing page
I do not want to create separate view as I already have User resource view page. I would like to display user view in a modal from Estimate listing page. If that make sense to you.
9 replies
FFilament
Created by H.Bilbao on 1/27/2024 in #❓┊help
Reuse form componenets
You can create separate class with static method that define form fields and then call that method in multiple resources, like this:
class MyFormFields
{
public static function form(): array
{
return [
Filament\Forms\Components\TextInput::make('name'),
...
];
}
}
class MyFormFields
{
public static function form(): array
{
return [
Filament\Forms\Components\TextInput::make('name'),
...
];
}
}
And then in your resource class:
class YourResourceClass
{
public static function form(Form $form): Form
{
return $form
->schema(...MyFormFields::form());
}
}
class YourResourceClass
{
public static function form(Form $form): Form
{
return $form
->schema(...MyFormFields::form());
}
}
4 replies
FFilament
Created by tjodalv on 1/27/2024 in #❓┊help
ViewAction on resource's table listing page
Can anyone help please?
9 replies
FFilament
Created by tjodalv on 1/27/2024 in #❓┊help
ViewAction on resource's table listing page
Oh yes and I also tried to use Filament\Actions\ViewAction instead of Filament\Tables\Actions\ViewAction but that didn't work either. If I use Filament\Tables\Actions\ViewAction, when clicking on, it opens view estimate page (I want to open user linked to estimate) and if I use Filament\Actions\ViewAction then nothing happens when clicking the button.
9 replies
FFilament
Created by tjodalv on 1/19/2024 in #❓┊help
customize creating related model in Select form component when using createOptionForm()
I didn't find a proper way to update my model after being created through Select component but I've managed to achieve what I wanted by using method afterStateUpdated() on Select form component and then checking if my Partner doesn't have assigned any type then assign the type that I want to be assigned. See an example:
Forms\Components\Select::make('partner_id')
->relationship(name: 'partner')
->createOptionForm([...])
->afterStateUpdated(function ($state, $set) {
$partnerId = (int) $state;
if ($partnerId === 0) return;

$partner = Partner::find($partnerId);
if (! $partner) return;

// If partner doesn't have a type defined the set type to client
if ($partner->types->count() === 0) {
$partner->types()->attach(
PartnerType::query()
->where('is_client', 1)
->orderBy('default_type', 'desc')
->first()?->id
??
null
);
}
})
Forms\Components\Select::make('partner_id')
->relationship(name: 'partner')
->createOptionForm([...])
->afterStateUpdated(function ($state, $set) {
$partnerId = (int) $state;
if ($partnerId === 0) return;

$partner = Partner::find($partnerId);
if (! $partner) return;

// If partner doesn't have a type defined the set type to client
if ($partner->types->count() === 0) {
$partner->types()->attach(
PartnerType::query()
->where('is_client', 1)
->orderBy('default_type', 'desc')
->first()?->id
??
null
);
}
})
5 replies
FFilament
Created by tjodalv on 1/19/2024 in #❓┊help
customize creating related model in Select form component when using createOptionForm()
The thing is that I do not want to change Partner form data, but I would like to assign relationship on newly created Partner model. That is the reason I tried to use using() method. But that method is not available on Filament\Forms\Components\Actions\Action class.
5 replies
FFilament
Created by tjodalv on 11/17/2023 in #❓┊help
How to update form field from resource Edit page's method?
After some more debugging problem was the way I was updating the value. This is foreach loop that made everything working fine:
$items = $this->data['taskItems'];

foreach($items as $key => $item) {
if ($item['product_id'] == $productId) {
// THIS IS HOW TO UPDATE PROPERTY INSIDE DATA ARRAY
$this->data['taskItems'][$key]['stock'] = $stock;
break;
}
}
$items = $this->data['taskItems'];

foreach($items as $key => $item) {
if ($item['product_id'] == $productId) {
// THIS IS HOW TO UPDATE PROPERTY INSIDE DATA ARRAY
$this->data['taskItems'][$key]['stock'] = $stock;
break;
}
}
I think that has nothing to do with filament but rather how PHP works.
4 replies
FFilament
Created by tjodalv on 11/17/2023 in #❓┊help
How to update form field from resource Edit page's method?
Update: If I dump all the form data in updateProductStock() method I can see that I've changed the quantity, but in the form it is still the old value. After foreach loop in my updateProductStock() method I've added:
dump($this->data);
dump($this->data);
When my livewire component dispatches 'update-stock' event, my method updateProductStock() is executed and modal pops up with dumped data. I can see that I've changed stock value, but it is not reflected in the form.
4 replies