How to access the record on a custom page?
I have tried with $record, $model, etc, nothing works
Solution:Jump to solution
What I do is instead of extending a
Page
, I extend to a ViewRecord
and overwrite the $view
paramater.
Then the $record
is usable in the view and actions work.
example:
```php...12 Replies
I have added this to my custom page, and seems to work. I don't know if is the best way, but works
public $record;
public function mount(Picking $record)
{
$this->record = $record;
}
Yes, looks good π
But my action buttons don't work, any idea about how to implement them?
What doesn't work exactly? What kind of error are you getting?
I click and nothign happens
Please share some code. How did you configure the actions?
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();
}
),
];
}
}
I'm using
protected function getActions(): array
{
return [
ViewAction::make(),
EditAction::make()
->visible(
function () {
return !$this->record->isDone();
}
),
];
}
as usual
Try
fn($record) => ! $record->isDone()
in your visible methods. I think you might be loosing the $this scope.I click and nothing happens
->url(static::getResource()::getUrl('view', ['record' => $this->record]))
this?Solution
What I do is instead of extending a
Page
, I extend to a ViewRecord
and overwrite the $view
paramater.
Then the $record
is usable in the view and actions work.
example:
this works and I'm doing this but I can't for the life of me get a CreateAction to work on the ViewRecord page to pop a modal.
no errors, no nothing. it just doesn't work. im trying to pop it in a wire:click to let "staff" manually add people to "event positions" while viewing an event. dd()ing my wire:click works fine, just nothing when it comes to the action. im really confused.
Thank you, it works. I tried it before and didn't work, no idea why.