F
Filamentβ€’16mo ago
fede8100

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
fede8100OPβ€’16mo 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
Patrick Boivinβ€’16mo ago
Yes, looks good πŸ‘
fede8100
fede8100OPβ€’16mo ago
But my action buttons don't work, any idea about how to implement them?
Patrick Boivin
Patrick Boivinβ€’16mo ago
What doesn't work exactly? What kind of error are you getting?
fede8100
fede8100OPβ€’16mo ago
I click and nothign happens
Patrick Boivin
Patrick Boivinβ€’16mo ago
Please share some code. How did you configure the actions?
fede8100
fede8100OPβ€’16mo 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
awcodesβ€’16mo ago
Try fn($record) => ! $record->isDone() in your visible methods. I think you might be loosing the $this scope.
LeandroFerreira
LeandroFerreiraβ€’16mo ago
I click and nothing happens ->url(static::getResource()::getUrl('view', ['record' => $this->record])) this?
Solution
Disouric
Disouricβ€’16mo 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
jerry55551β€’16mo 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
fede8100OPβ€’16mo ago
Thank you, it works. I tried it before and didn't work, no idea why.
Want results from more Discord servers?
Add your server