F
Filamentβ€’16mo 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'),
];
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;
}
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
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 πŸ™‚
7 Replies
krekas
krekasβ€’16mo ago
You aren't passing record to the route
kennyhorna
kennyhornaOPβ€’16mo ago
@krekas that's the idea. To avoid passing any id in the route in order to mask the path. I can resolve the record using the logged in user. Similar to how any generic /profile should work. I would like for customers to access their business details by going into /my-business
Dennis Koch
Dennis Kochβ€’16mo ago
It's not that easy to create an EditPage without a record. I think it's also used in mount() method which you cannot override.
kennyhorna
kennyhornaOPβ€’16mo ago
@Dennis Koch I see. How can I achieve something like this? I tried before creating a custom page and to add an infolist to a livewire component following https://filamentphp.com/docs/3.x/infolists/adding-an-infolist-to-a-livewire-component but it's not clear. It tells you to implement the HasInfolists interface but then you need to add:
public function getInfolist(string $name): ?Infolist
{
// what is that $name value?
}
public function getInfolist(string $name): ?Infolist
{
// what is that $name value?
}
krekas
krekasβ€’16mo ago
custom page
Dennis Koch
Dennis Kochβ€’16mo ago
but then you need to add:
You don't if you follow the instructions. There's a trait which adds all the methods for you.
kennyhorna
kennyhornaOPβ€’16mo ago
@Dennis Koch my bad I totally missed the traits. Now it works as expected. Thanks.
Want results from more Discord servers?
Add your server