tjodalv
tjodalv
FFilament
Created by tjodalv on 8/31/2024 in #❓┊help
Problem with Import Action - Import job never completes
I am having a problem with ImportAction. I want to use it to import products from CSV file. I am testing it with CSV file that has two rows in total. But when I run the action, job keep executing endlessly over and over, spamming failed_import_rows table. I am not sure why is it doing so. If it fails to import the records is should end the job in the end. I also created custom App\Jobs\ImportCsv job class that extends Filament\Actions\Imports\Jobs\ImportCsv job class and added property public $tries = 1; but that doesn't work either. If I inspect jobs table in the database I can see that the number of attempts is ridiculesly high, e.g. 15346. Then I need to stop the worker, remove the job from jobs table and clear the failed_import_rows table. This is how I resolve records in my importer class:
public function resolveRecord(): ?Product
{
if (! array_key_exists('ID', $this->data) || blank($this->data['ID'])) {
return new Product();
}

return Product::firstOrNew(['id' => $this->data['ID']]);
}
public function resolveRecord(): ?Product
{
if (! array_key_exists('ID', $this->data) || blank($this->data['ID'])) {
return new Product();
}

return Product::firstOrNew(['id' => $this->data['ID']]);
}
Other then that I just have a bunch of columns defined on the Importer and using afterSave() hook to perform product stock update, as I keep stocks in separate table. In the fail_import_rows table validation_error column is always NULL.
9 replies
FFilament
Created by tjodalv on 3/13/2024 in #❓┊help
ImportAction job is failing but there is no error message
I have simple table with dozens of fields. Nothing special. I want to import records with Filament ImportAction. I am able to select file, then I get to choose to map CSV fields with database fields. After I click import, the job is dispatched, but the problem is that job is never completed. I see in my terminal window where I am running php artisan queue:work that ImportCsv job is failing: 2024-03-13 19:36:32 Filament\Actions\Imports\Jobs\ImportCsv .............................................................................. RUNNING 2024-03-13 19:36:32 Filament\Actions\Imports\Jobs\ImportCsv ......................................................................... 56.26ms FAIL And the job is running and failing, running and failing over and over again. But the job is never added to fail_jobs table. I get import error for every row in the CSV file and my failed_import_rows table is filled with thousand of records but for each row validation_error field is set to NULL. My CSV file is not big it has 65 rows, so that should be 65 records but the job is stuced in a loop. I need to stop laravel queue worker and delete the job from the jobs table. This is how I run my queue worker
php artisan queue:work --tries=3
php artisan queue:work --tries=3
8 replies
FFilament
Created by tjodalv on 2/21/2024 in #❓┊help
Action inside modal is not working
Hi I have action that open a modal with custom view. On that view I have another action but when I click on that action nothing happens:
\Filament\Tables\Actions\Action::make('openPaymentModal')
->icon(...)
->label('Open payments')
->modalContent(function ($record) {
$removePaymentAction = DeleteAction::make('removePayment')
->hiddenLabel()
->size('sm')
->icon('heroicon-s-x-mark');

return view('filament.modals.payments-list', compact(
'record',
'removePaymentAction'
));
})
\Filament\Tables\Actions\Action::make('openPaymentModal')
->icon(...)
->label('Open payments')
->modalContent(function ($record) {
$removePaymentAction = DeleteAction::make('removePayment')
->hiddenLabel()
->size('sm')
->icon('heroicon-s-x-mark');

return view('filament.modals.payments-list', compact(
'record',
'removePaymentAction'
));
})
And this is my /resources/filament/modals/payments-list.blade.php file:
@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->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">{{ $removePaymentAction->record($payment) }}</td>
</tr>
@endforeach
I am setting record on my $removePaymentAction button inside foreach loop. When I click on that button, spinner show and then disappear and nothing happens. The record doesn't get deleted. Confirmation dialog also is not triggering. Can someone help?
12 replies
FFilament
Created by tjodalv on 2/20/2024 in #❓┊help
Remove badge from filter action trigger button if there are no active filters
Hi I would like to remove badge that shows how many filters are currently active if there are no active filters applied to filament table. What would be the easiest way to do it?
2 replies
FFilament
Created by tjodalv on 1/29/2024 in #❓┊help
How to switch eloquent record context for table action
I have a table action that when clicked open infolist. But I want to change the eloquent record context for that infolist. I've tried with mountUsing but with no luck:
\Filament\Tables\Actions\Action::make('my-action')
->mountUsing(function ($action, App\Models\SomeModel $record) {
$otherModel = App\Models\OtherModel::find(1);
// Here I am trying to switch record context for my action infolist but unfortunately it doesn't work. Infolist still gets data from SomeModel
$action->record($otherModel);
})
->infolist([
TextEntry::make('name')
->label('This should be populated from OtherModel')
])
\Filament\Tables\Actions\Action::make('my-action')
->mountUsing(function ($action, App\Models\SomeModel $record) {
$otherModel = App\Models\OtherModel::find(1);
// Here I am trying to switch record context for my action infolist but unfortunately it doesn't work. Infolist still gets data from SomeModel
$action->record($otherModel);
})
->infolist([
TextEntry::make('name')
->label('This should be populated from OtherModel')
])
If I use form then I can bind different record in mountUsing by calling $form->model($otherModel); and then $form->fill($otherModel->toArray());
2 replies
FFilament
Created by tjodalv on 1/27/2024 in #❓┊help
ViewAction on resource's table listing page
Hi, I have a model Estimate that has relationship to other model User. I want from ListEstimate page to have action that will open user info in a modal window (slideover). How to achive that? What I tried so far didn't work:
Tables\Actions\ViewAction::make('view-user')
->label('Show user')
->slideOver(true)
->record(fn ($record) => User::find($record->user_id));
Tables\Actions\ViewAction::make('view-user')
->label('Show user')
->slideOver(true)
->record(fn ($record) => User::find($record->user_id));
9 replies
FFilament
Created by tjodalv on 1/19/2024 in #❓┊help
customize creating related model in Select form component when using createOptionForm()
Hi I have a Select form component that is connected with relationship named 'partner' and I want to enable users to create a partner from Select component by using ->createOptionForm() method. My Partner model has many-to-many relationship to PartnerType model and I want set that relationship when creating new Partner, but I do not want the user is able to select partner type. I want to assign fixed partner type when new partner is created. What would be the best way to achieve that? I've tried something like this, but Filament said that ComponentAction doesn't have using() method:
Forms\Components\Select::make('partner_id')
->relationship(name: 'partner')
->createOptionForm([...])
->createOptionAction(fn (Forms\Components\Actions\Action $action) =>
$action
->label('New partner')
->using(function (array $data, Partner $model) {
return $model::create($data)->types()->attach(
PartnerType::query()
->where('is_client', 1)
->first()?->id
??
null
);
})
)
Forms\Components\Select::make('partner_id')
->relationship(name: 'partner')
->createOptionForm([...])
->createOptionAction(fn (Forms\Components\Actions\Action $action) =>
$action
->label('New partner')
->using(function (array $data, Partner $model) {
return $model::create($data)->types()->attach(
PartnerType::query()
->where('is_client', 1)
->first()?->id
??
null
);
})
)
5 replies
FFilament
Created by tjodalv on 11/17/2023 in #❓┊help
How to update form field from resource Edit page's method?
I have resource edit form. In one placeholder field I am including my custom Livewire component. My Livewire component dispatches event 'update-stock' and with event it is sending $productId and $stock info. I am listening for that event on my resource edit page and when method is triggered I want to update stock field in the underlying form. But for some reason that stock variable doesn't change. This is code from my resource edit page:
// app/Filament/Resources/TaskResource/Pages/EditTask.php
...
protected $listeners = ['update-stock' => 'updateProductStock'];

public function updateProductStock($args)
{
$productId = $args['product_id'];
$stock = $args['stock'];
// $args are array holding 'productId' and 'stock' key
// here I want to update field that is inside of the repeater field
// repeater field is called 'taskItems' and every repeater item
// has fields 'product_id' and 'stock'. This is what I was trying to do:
$items = $this->data['taskItems'];

foreach($items as $item) {
if ($item['product_id'] == $productId) {
$item['stock'] = $stock;
break;
}
}
}
...
// app/Filament/Resources/TaskResource/Pages/EditTask.php
...
protected $listeners = ['update-stock' => 'updateProductStock'];

public function updateProductStock($args)
{
$productId = $args['product_id'];
$stock = $args['stock'];
// $args are array holding 'productId' and 'stock' key
// here I want to update field that is inside of the repeater field
// repeater field is called 'taskItems' and every repeater item
// has fields 'product_id' and 'stock'. This is what I was trying to do:
$items = $this->data['taskItems'];

foreach($items as $item) {
if ($item['product_id'] == $productId) {
$item['stock'] = $stock;
break;
}
}
}
...
As you can see I was trying to manipulate field values directly in $data array, but that doesn't work. When form is rendered I still see old stock value in the form.
4 replies
FFilament
Created by tjodalv on 11/10/2023 in #❓┊help
Bind different model to action form
I've created action with form that I am calling from some resource edit page. Model binded to that action form is the model that belongs to the resource from which I am calling that action. What I want is to bind completely different model to that action form that have no relation to underlying model. Any ideas how to do that. Example what I would like to do:
Filament\Forms\Components\Actions\Action::make('new_product')
// I know there is no setModel() method on action
->setModel(Product::class)
->form([
TextInput::make('product_name')->required(),
Select::make('product_type_id')
->relationship(name: 'type', titleAttribute: 'name')
])
->action(function () {
// When action is executed I want to create new product
});
Filament\Forms\Components\Actions\Action::make('new_product')
// I know there is no setModel() method on action
->setModel(Product::class)
->form([
TextInput::make('product_name')->required(),
Select::make('product_type_id')
->relationship(name: 'type', titleAttribute: 'name')
])
->action(function () {
// When action is executed I want to create new product
});
And that action button is called from PageResource edit page that is why I am creating Filament\Components\Actions\Action. My form in action is in no relation to a underlying Page model, and I want to be bind to Product model.
11 replies
FFilament
Created by tjodalv on 10/26/2023 in #❓┊help
Validate form from custom Action button - maybe bug
I've added custom action button on resource edit page and I want to validate form before proceeding with action. There is strange bug or weird behaviour. This is my action button:
class EditTask extends EditRecord
{
protected static string $resource = TaskResource::class;

protected function getHeaderActions(): array
{
return [
Actions\Action::make('Complete task')
->action(function () {
// I've found somewhere on discord that this validates form.
// It does but only the first time when this action is executed,
// if you click on the button again then empty modal is opened
// with two buttons Submit and Cancel ?!?
$this->form->getState();

// after validation form should be saved
$this->save();

// the rest of action code should be here
}),
Actions\ViewAction::make(),
Actions\DeleteAction::make(),
];
}
}
class EditTask extends EditRecord
{
protected static string $resource = TaskResource::class;

protected function getHeaderActions(): array
{
return [
Actions\Action::make('Complete task')
->action(function () {
// I've found somewhere on discord that this validates form.
// It does but only the first time when this action is executed,
// if you click on the button again then empty modal is opened
// with two buttons Submit and Cancel ?!?
$this->form->getState();

// after validation form should be saved
$this->save();

// the rest of action code should be here
}),
Actions\ViewAction::make(),
Actions\DeleteAction::make(),
];
}
}
3 replies