How to access the record on a custom page?

I have tried with $record, $model, etc, nothing works
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...
Jump to solution
12 Replies
fede8100
fede8100OP2y ago
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; }
Patrick Boivin
Yes, looks good 👍
fede8100
fede8100OP2y ago
But my action buttons don't work, any idea about how to implement them?
Patrick Boivin
What doesn't work exactly? What kind of error are you getting?
fede8100
fede8100OP2y ago
I click and nothign happens
Patrick Boivin
Please share some code. How did you configure the actions?
fede8100
fede8100OP2y ago
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
awcodes
awcodes2y ago
Try fn($record) => ! $record->isDone() in your visible methods. I think you might be loosing the $this scope.
LeandroFerreira
I click and nothing happens ->url(static::getResource()::getUrl('view', ['record' => $this->record])) this?
Solution
Disouric
Disouric2y ago
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

namespace App\Filament\Resources\ChargerResource\Pages;

use App\Filament\Resources\ChargerResource;
use Filament\Resources\Pages\ViewRecord;

class ChargerTransactions extends ViewRecord
{
protected static string $resource = ChargerResource::class;

protected static string $view = 'chargers.transactions';
}
<?php

namespace App\Filament\Resources\ChargerResource\Pages;

use App\Filament\Resources\ChargerResource;
use Filament\Resources\Pages\ViewRecord;

class ChargerTransactions extends ViewRecord
{
protected static string $resource = ChargerResource::class;

protected static string $view = 'chargers.transactions';
}
jerry55551
jerry555512y ago
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.
fede8100
fede8100OP2y ago
Thank you, it works. I tried it before and didn't work, no idea why.

Did you find this page helpful?