欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

Subdomain route::resource "mandatory parameters are missing"

I'm having trouble posting data when using subdomain routes and a resource controller.

Route::group(array('domain' => '{subdomain}.' . Config::get('app.domain')), function()
{
    //Resources
    Route::resource('project', 'ProjectsController');
});

// Adding this resolves the issue
// Route::resource('project', 'ProjectsController');

When I try to set the action of my form to the store method:

{{ Form::open(array('action' => 'ProjectsController@store')) }}

I get the following error:

MissingMandatoryParametersException: Some mandatory parameters are missing ("subdomain") to generate a URL for route "project.store".

Also another issue when redirecting:

return Redirect::action('ProjectsController@show', array('1'));  // Error (see below)
return Redirect::action('ProjectsController@show', array('mysubdomain', '1'));  // Works, when manually passing the subdomain, but is this required?

InvalidParameterException: Parameter "project" for route "project.show" must match "[^/]++" ("" given) to generate a corresponding URL.

Adding the subdomain as extra parameter to the form does not resolve the issue.
Any idea what the problem could be?

Thanks!

 
@taylorotwell
Owner

taylorotwell commented on Apr 6 2013

On the Form thing, you need to do something like:

Form::open(['action' => ['ProjectsController@store', 'subdomain', '1']]);

As far as passing the sub-domain, yes, that is currently required since it is a wildcard parameter. We can try to come up with some kind of helper there that uses the current domain if one is not specified, but I will have to look into it.

 

 taylorotwell closed this on Apr 7 2013

 来自  https://github.com/laravel/framework/issues/844

Subdomain route conflicts with ressource controllers #1201

 Closed
remluben opened this issue on May 6 2013 · 2 comments

Comments

 
Projects
None yet
2 participants
@remluben@jasonlewis
@remluben

remluben commented on May 6 2013

I ran into an issue when using a subdomain route with a ressource controller:

Route::group(array('domain' => 'api.example.{tld}'), function()
{ 
    Route::resource('game', 'GameController');
});

When making the GET request for a single ressource with ID 1 ( api.example.test/game/1 ) the Game::find($id) throws a ModelNotFoundException always.

I finally found out, that the $id parameter within my GameController::show() Method had value 'test'. It seems as if the value catched from the domain name within the {tld} expression is provided as a parameter for this method by the laravel framework.

I am new to Laravel / Laravel 4, so I really hope, that this is not a mistake I made.

 
@jasonlewis
Contributor

jasonlewis commented on May 6 2013

The parameters are passed in from left to right (or outer to inner). Your ID parameter will be the second parameter of your method.

 
@remluben

remluben commented on May 7 2013

Thanks a lot for your information. Maybe this would be something to point out within the L4 documentation at http://four.laravel.com/docs/routing#sub-domain-routing to clearify things, as the example somehow didn't show this use case of domain routing. For me it seemed as if the parameter from the subdomain is available within the route closures only.

 

普通分类: