Skip to content

"Missing required parameter for Route" error with resource routing #18

@cowgod

Description

@cowgod

I'm not sure if this is a bug or just lack of understanding on my part, as I'm fairly new to Laravel. I'm trying to implement this package in the Laravel app I'm building, but I'm running into an issue getting resource routing to work, in a case where the parent for the show route for one (nested) resource needs to be the show route for its parent resource. I can't find a way to define the breadcrumb for the child show route that loads without error.

What version does this affect?

  • Laravel Version: 10.34.2
  • Package Version: 1.7.0

To Reproduce

Here is the relevant excerpt from the routes/web.php file:

	Route::get('/', function () {
		return view('home');
	})
	     ->name('home')
	     ->breadcrumb('Home')
	;


	Route::resource('repositories', RepositoryController::class)
	     ->only(['index', 'show'])
	     ->breadcrumbs(function (ResourceBreadcrumbs $breadcrumbs) {
		     $breadcrumbs
			     ->index('Repositories')
			     ->show(fn(Repository $repository) => $repository->name)
		     ;
	     })
	;

	Route::resource('repositories.repository_accounts', RepositoryAccountController::class)
	     ->only(['index', 'show'])
	     ->breadcrumbs(function (ResourceBreadcrumbs $breadcrumbs) {
		     $breadcrumbs
			     ->index('Accounts')
			     ->show(fn(RepositoryAccount $ra) => $ra->identifier)
//			     ->show(fn(RepositoryAccount $ra) => $ra->identifier, 'repositories.show')
//			     ->show(fn(RepositoryAccount $ra) => $ra->identifier, 'repositories.show', fn(RepositoryAccount $ra) => $ra->repository)
		     ;
	     })
	;

As you can see, I've tried three different alternatives of the show() function for the child resource. Neither works, but they give different errors when trying to access the child resource's show route:


show(fn(RepositoryAccount $ra) => $ra->identifier)

Error:
Missing required parameter for [Route: repositories.repository_accounts.index] [URI: repositories/{repository}/repository_accounts] [Missing parameter: repository].


show(fn(RepositoryAccount $ra) => $ra->identifier, 'repositories.show')

Error: Illuminate\Routing\RouteFileRegistrar::{closure}(): Argument #1 ($ra) must be of type App\Models\RepositoryAccount, App\Models\Repository given, called in /app/vendor/glhd/gretel/src/Resolvers/Resolver.php on line 35


show(fn(RepositoryAccount $ra) => $ra->identifier, 'repositories.show', fn(RepositoryAccount $ra) => $ra->repository)

Error: Illuminate\Routing\RouteFileRegistrar::{closure}(): Argument #1 ($ra) must be of type App\Models\RepositoryAccount, App\Models\Repository given, called in /app/vendor/glhd/gretel/src/Resolvers/Resolver.php on line 35


Expected behavior
The child's show route loads successfully.

Additional context

It may be relevant that I'm also using slugs for my models' route keys, using Spatie's laravel-sluggable package, so the route for the show endpoint on my child resource resource looks like /repositories/active-directory/repository_accounts/abigailbruen. However, I've tested disabling the getRouteKey() definitions in both the parent and child model, which results in my route looking like /repositories/1/repository_accounts/9, and the problem still occurs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions