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

URL generation for named resource controller #182

Closed
GaryJones opened this issue Jan 27, 2013 · 3 comments
Closed

URL generation for named resource controller #182

GaryJones opened this issue Jan 27, 2013 · 3 comments

Comments

@GaryJones
Copy link

In my routes.php I have a resourceful route / controller:
Route::resource('manager', 'Battrick\Manager', ['only' => ['index', 'show', 'create']]);

In my Home.php controller, I insert a HTML link, with a named resourceful route, with:
\URL::route('manager.show', array('id' => '11287')) for the href as I want to link to a particular Manager.

However, when calling the home page, I get the following error:


MissingMandatoryParametersException: Some mandatory parameters are missing ("manager") to generate a URL for route "manager.show".

  1. in ...\vendor\symfony\routing\Symfony\Component\Routing\Generator\UrlGenerator.php line 155
  2. at UrlGenerator->doGenerate( array('manager') , array(), array('_method' => 'get'), array(array('variable', '/', '[^/]++', 'manager'), array('text', '/manager')), array('id' => '11287'), 'manager.show', true, array()) in ...\vendor\symfony\routing\Symfony\Component\Routing\Generator\UrlGenerator.php line 140
  3. at UrlGenerator->generate('manager.show', array('id' => '11287'), true) in ...\vendor\laravel\framework\src\Illuminate\Routing\UrlGenerator.php line 150
  4. at UrlGenerator->route('manager.show', array('id' => '11287')) in ...\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php line 108

(my emphasis)

I've tried digging down into the Symfony Routing files, but couldn't quite follow why the array('manager') (highlighted) was getting set as the first argument of doGenerate(), which then gets used as a check against which parameters were passed (here, just the array('id' => '11287') as I believe it should be), and therefore failing.

Is this a Symfony issue (if so, could someone who can explain it better please pass it upstream), is it some issue with the choice of naming format for named routes for resource controllers in L4, or am I doing something wrong?

@GaryJones
Copy link
Author

OK, so the {manager} parameter is being added in addResourceShow(), but that leads to the following inconsistency:

To reach a standard named route I need:
\URL::route('foobar', array('id' => '11287'))

To reach a resource controller named route I need:
\URL::route('foobar.show', array('foobar' => '11287'))

Is that the way it was meant to work? Has {id} been dropped as the default parameter for single items? (Not mentioned or reflected in the docs)

@taylorotwell
Copy link
Member

Yes, {id} has been dropped. However, I should point out, you don't have to specify keys at all:

URL::route('foobar.show', array(11287));

will work fine...

{id} was dropped so that resource routes work well with the new Route::model method, which will be documented upon the release of beta 2.

@GaryJones
Copy link
Author

Is the dropping of keys for all routes, or only those created via resource controllers?

joelharkes added a commit to joelharkes/framework_old that referenced this issue Mar 7, 2019
…tional-info

Finished back-end work for this branch. Todo: match with front-end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants