F
Filament6mo ago
sven

Only allow to edit one record in my resource

Hey! Is it possible to have a filament ressource but skip the view which lists all records and always navigate to the edit-route of a specific record? I tried something like this:
// ProfileResource.php

public static function getPages(): array
{
return [
// I named it index so that it is still
// in the navigation
'index' => Pages\EditProfile::route('/'),
];
}

// ProfileResourse/Pages/EditProfile.php
class EditProfile extends EditRecord
{
protected static string $resource = ProfileResource::class;

// I am doing this so the route can be visited without
// providing the ID to the URL
public function mount(): void
{
$this->record = $this->resolveRecord(auth()->user()->profile());

$this->authorizeAccess();

$this->fillForm();

$this->previousUrl = url()->previous();
}
// ProfileResource.php

public static function getPages(): array
{
return [
// I named it index so that it is still
// in the navigation
'index' => Pages\EditProfile::route('/'),
];
}

// ProfileResourse/Pages/EditProfile.php
class EditProfile extends EditRecord
{
protected static string $resource = ProfileResource::class;

// I am doing this so the route can be visited without
// providing the ID to the URL
public function mount(): void
{
$this->record = $this->resolveRecord(auth()->user()->profile());

$this->authorizeAccess();

$this->fillForm();

$this->previousUrl = url()->previous();
}
This approach can not work because i am overloading mount with the wrong number of arguments.
2 Replies
sven
svenOP6mo ago
I was hoping to profit from some of the work that EditRecord is already doing for me. But maybe I am overestimating what it does? - Adds the form - Handles save-confirmation - Rollbacks in case of exceptions Does that sound right? The alternative is to redirect the list-action ^^'
class ListProfiles extends ListRecords
{
protected static string $resource = ProfileResource::class;

public function mount(): void
{
$this->redirectRoute('filament.admin.resources.profiles.edit', [ 'record' => auth()->user()->profile->id]);
}
class ListProfiles extends ListRecords
{
protected static string $resource = ProfileResource::class;

public function mount(): void
{
$this->redirectRoute('filament.admin.resources.profiles.edit', [ 'record' => auth()->user()->profile->id]);
}
Is creating a custom page for this the common approach?
Want results from more Discord servers?
Add your server