Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cowgod opened this issue Dec 20, 2023 · 1 comment
Open
Labels
bug Something isn't working

Comments

@cowgod
Copy link

cowgod commented Dec 20, 2023

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.

@cowgod cowgod added the bug Something isn't working label Dec 20, 2023
@just-tom
Copy link

just-tom commented Apr 9, 2024

@cowgod Did you find a solution for this in the end? Im facing the same thing using uuids as my route model binding key.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants