F
Filament4mo ago
Tug

Issues with nested resources (maybe)

Hi everyone, has anyone encountered issues with nested resources? I set up a resource for a model called PersonnelProfile and nested a resource for the Contract model within it. The resulting URL looked something like mydomain.com/personnel-profiles/2/contracts/create, but I got a 'file not found' error. However, as a test, I created a model named Profile and nested the contract there, which worked correctly. Could I be making a mistake by naming it PersonnelProfile in the first place? Maybe the hyphens in the url or something else?
3 Replies
Dan Harrin
Dan Harrin4mo ago
What was the specific "file not found" error?
Tug
TugOP4mo ago
Hi!! I tried with another model called JobProfile, where I attempted to nest the Phone resource, but the error was the same—it correctly shows the index, but the create action returns a 404 Not Found. On the other hand, the one I created without hyphens in the url, named Profile, allowed me to properly nest the Contract resource.
No description
No description
Tug
TugOP4mo ago
Also, I used a Relation Page to access the nested resource: php artisan make:filament-page ManageJobProfilePhones --resource=JobProfiles\JobProfileResource --type=ManageRelatedRecords These are my getPage and getRecordSubNavigation functions in my JobProfileResource:
public static function getPages(): array
{
return [
'index' => ListJobProfiles::route('/'),
'create' => CreateJobProfile::route('/create'),
'view' => ViewJobProfile::route('/{record}'),
'edit' => EditJobProfile::route('/{record}/edit'),
'phones' => ManageJobProfilePhones::route('/{record}/phones'),
];
}

public static function getRecordSubNavigation(Page $page): array
{
return $page->generateNavigationItems([
ViewJobProfile::class,
EditJobProfile::class,
ManageJobProfilePhones::class,

]);
}
public static function getPages(): array
{
return [
'index' => ListJobProfiles::route('/'),
'create' => CreateJobProfile::route('/create'),
'view' => ViewJobProfile::route('/{record}'),
'edit' => EditJobProfile::route('/{record}/edit'),
'phones' => ManageJobProfilePhones::route('/{record}/phones'),
];
}

public static function getRecordSubNavigation(Page $page): array
{
return $page->generateNavigationItems([
ViewJobProfile::class,
EditJobProfile::class,
ManageJobProfilePhones::class,

]);
}

Did you find this page helpful?