php - Laravel Route - Nested Resource Controllers without intermediate page -
i have 2 controllers - chcontroller & fillcontroller . chcontroller works fine.
route::resource('c', 'chcontroller'); | | get|head | c | c.index | app\http\controllers\chcontroller@index | | | | get|head | c/create | c.create | app\http\controllers\chcontroller@create | | | | post | c | c.store | app\http\controllers\chcontroller@store | | | | get|head | c/{c} | c.show | app\http\controllers\chcontroller@show | | | | get|head | c/{c}/edit | c.edit | app\http\controllers\chcontroller@edit | | | | put | c/{c} | c.update | app\http\controllers\chcontroller@update | | | | patch | c/{c} | | app\http\controllers\chcontroller@update | | | | delete | c/{c} | c.destroy | app\http\controllers\chcontroller@destroy | |
but need nested fillcontroller (f), like:
/c/{c}/create /c/{c}/{f} /c/{c}/{f}/show /c/{c}/{f}/edit // etc...
i tried:
route::group(['prefix' => 'c/{c}'], function () { route::resource('{f}', 'fillcontroller'); }); | | get|head | c/{c}/{f} | c.{c}.{f}.index | app\http\controllers\fillcontroller@index | | | | get|head | c/{c}/{f}/create | c.{c}.{f}.create | app\http\controllers\fillcontroller@create | | | | post | c/{c}/{f} | c.{c}.{f}.store | app\http\controllers\fillcontroller@store | | | | get|head | c/{c}/{f}/{{f}} | c.{c}.{f}.show | app\http\controllers\fillcontroller@show | | | | get|head | c/{c}/{f}/{{f}}/edit | c.{c}.{f}.edit | app\http\controllers\fillcontroller@edit | | | | put | c/{c}/{f}/{{f}} | c.{c}.{f}.update | app\http\controllers\fillcontroller@update | | | | patch | c/{c}/{f}/{{f}} | | app\http\controllers\fillcontroller@update | | | | delete | c/{c}/{f}/{{f}} | c.{c}.{f}.destroy | app\http\controllers\fillcontroller@destroy | | route::group(['prefix' => 'c/{c}'], function () { route::resource('f', 'fillcontroller'); }); | | get|head | c/{c}/f | c.{c}.f.index | app\http\controllers\fillcontroller@index | | | | get|head | c/{c}/f/create | c.{c}.f.create | app\http\controllers\fillcontroller@create | | | | post | c/{c}/f | c.{c}.f.store | app\http\controllers\fillcontroller@store | | | | get|head | c/{c}/f/{f} | c.{c}.f.show | app\http\controllers\fillcontroller@show | | | | get|head | c/{c}/f/{f}/edit | c.{c}.f.edit | app\http\controllers\fillcontroller@edit | | | | put | c/{c}/f/{f} | c.{c}.f.update | app\http\controllers\fillcontroller@update | | | | patch | c/{c}/f/{f} | | app\http\controllers\fillcontroller@update | | | | delete | c/{c}/f/{f} | c.{c}.f.destroy | app\http\controllers\fillcontroller@destroy | |
all of them makes intermediate page /f/ , don't need.
the close that:
route::group(['prefix' => 'c/{c}'], function () { route::resource('', 'fillcontroller'); }); | | get|head | c/{c}/create | c.{c}..create | app\http\controllers\fillcontroller@create | | | | post | c/{c} | c.{c}..store | app\http\controllers\fillcontroller@store | | | | get|head | c/{c}/{} | c.{c}..show | app\http\controllers\fillcontroller@show | | | | get|head | c/{c}/{}/edit | c.{c}..edit | app\http\controllers\fillcontroller@edit | | | | put | c/{c}/{} | c.{c}..update | app\http\controllers\fillcontroller@update | | | | patch | c/{c}/{} | | app\http\controllers\fillcontroller@update | | | | delete | c/{c}/{} | c.{c}..destroy | app\http\controllers\fillcontroller@destroy | |
but router doesn't know {f} parameter.
first of f
not an intermediate page refer it, it's uri segment. , it's way go, because saying subresource (f
) being accessed. suggest stick it.
now if still want go way, can achieve 1 exception. can't have index
route f
subresource in naming scheme because overwrite show
c
resource.
route::group(['prefix' => 'c/{c}'], function () { // can't have because overwrite c.show // route::get('/', ['as' => 'f.index', 'uses' => 'fillcontroller@index']); route::get('/create', ['as' => 'f.create', 'uses' => 'fillcontroller@create']); route::post('/', ['as' => 'f.store', 'uses' => 'fillcontroller@store']); route::get('/{f}/edit', ['as' => 'f.edit', 'uses' => 'fillcontroller@edit']); route::put('/{f}', ['as' => 'f.update', 'uses' => 'fillcontroller@update']); route::patch('/{f}', 'fillcontroller@update'); route::delete('/{f}', ['as' => 'f.destroy', 'uses' => 'fillcontroller@destroy']); });
| | get|head | c | c.index | app\http\controllers\chcontroller@index | | | | get|head | c/create | c.create | app\http\controllers\chcontroller@create | | | | post | c | c.store | app\http\controllers\chcontroller@store | | | | get|head | c/{c} | f.index | app\http\controllers\fillcontroller@index | | | | get|head | c/{c}/edit | c.edit | app\http\controllers\chcontroller@edit | | | | put | c/{c} | c.update | app\http\controllers\chcontroller@update | | | | patch | c/{c} | | app\http\controllers\chcontroller@update | | | | delete | c/{c} | c.destroy | app\http\controllers\chcontroller@destroy | | | | get|head | c/{c}/create | f.create | app\http\controllers\fillcontroller@create | | | | post | c/{c} | f.store | app\http\controllers\fillcontroller@store | | | | get|head | c/{c}/{f}/edit | f.edit | app\http\controllers\fillcontroller@edit | | | | put | c/{c}/{f} | f.update | app\http\controllers\fillcontroller@update | | | | patch | c/{c}/{f} | | app\http\controllers\fillcontroller@update | | | | delete | c/{c}/{f} | f.destroy | app\http\controllers\fillcontroller@destroy | |
Comments
Post a Comment