fede8100
How to get $data in Tables\Actions\CreateAction::make()?
In a RelationManager, in the Table, I have this code "return $table
->headerActions([
Tables\Actions\CreateAction::make()
->createAnother(false)
->before(function (RelationManager $livewire, array $data, Tables\Actions\CreateAction $action) {
if ($data['total'] > 0) {
} else { Notification::make() ->title('It was canceled, the value can't be zero') ->warning() ->send(); $action->cancel(); } }) ->after(function (RelationManager $livewire, CreditNote $record, array $data) {
}), ])" This code was working since months ago, I used to access the $data array with the data in the form. But since a few updates ago, first $data didn't include the disabled() components, but now it seems that I can't access the $data anymore in the before() method, so I can't control that everything is fine or do an action based on the form data.
} else { Notification::make() ->title('It was canceled, the value can't be zero') ->warning() ->send(); $action->cancel(); } }) ->after(function (RelationManager $livewire, CreditNote $record, array $data) {
}), ])" This code was working since months ago, I used to access the $data array with the data in the form. But since a few updates ago, first $data didn't include the disabled() components, but now it seems that I can't access the $data anymore in the before() method, so I can't control that everything is fine or do an action based on the form data.
5 replies
How to access the record on a custom page?
namespace Elfeffe\FilamentCerebro\Resources\DeliveryNoteResource\Pages;
use Elfeffe\FilamentCerebro\Resources\DeliveryNoteResource;
use Filament\Pages\Actions\EditAction;
use Filament\Pages\Actions\ViewAction;
use Filament\Pages\Concerns\HasFormActions;
use Filament\Resources\Pages\Concerns\HasRecordBreadcrumb;
use Filament\Resources\Pages\Concerns\InteractsWithRecord;
use Filament\Resources\Pages\Page;
class ScanDeliveryNote extends Page
{
use InteractsWithRecord;
use HasFormActions;
use HasRecordBreadcrumb;
protected static string $resource = DeliveryNoteResource::class;
protected static string $view = 'filament-cerebro::filament.resources.delivery-note-resource.pages.scan-delivery-note';
public function mount($record): void
{
static::authorizeResourceAccess();
$this->record = $this->resolveRecord($record);
abort_unless(static::getResource()::canView($this->getRecord()), 403);
}
protected function getActions(): array
{
return [
ViewAction::make(),
EditAction::make()
->visible(
function () {
return !$this->record->isDone();
}
),
];
}
}
18 replies
I think lte validator is not working
I had to use
->rules([
function (RelationManager $livewire) {
return function (string $attribute, $value, \Closure $fail) use($livewire) {
if (round($value, 2) > round($livewire->ownerRecord->grand_total, 2)) {
$fail("The amount can't be bigger than the order's amount.");
}
};
},
])
5 replies