FilamentF
Filamentβ€’3y ago
kennyhorna

Set record in ViewRecord page

Hi, I'm creating a custom panel for a customer role. So I would like to limit the view/edit actions for this customer to only be able manage his/hers business.

So my idea is to create BusinessResource and then use the ViewBusiness to display the data using an infolist, so then I can add a new entry in the nav pointing to the view page directly.

My problem right now is that I cannot set the record in the view page.

So this is my Business::getPages():
return [
    'view' => Pages\ViewBusiness::route('/my-business'),
];


I've tried to set the record using this 3 methods but so far no luck:

public function getRecord(): Model
{
    return auth()->user()->business;
}

protected function resolveRecord(int|string|null $key): Model
{
    return auth()->user()->business;
}

public function setRecord(Model|int|string|null $record): void
{
    $this->record = auth()->user()->business;
}


But I'm still getting:
Unable to resolve dependency [Parameter #0 [ <required> string|int $record ]] in class Filament\Resources\Pages\ViewRecord


How could I achieve this? Or maybe some guidance in case there's an easier approach.

Thanks in advance πŸ™‚
Was this page helpful?