Laravel 4 nested resource controllers Route :: resource ('admin / photo', 'PhotoController'); does not work

In Larvel 4, I am trying to install nested resource controllers.

in routes.php :

Route::resource('admin/photo', 'Controllers\\Admin\\PhotoController'); 

in application \ controllers \ Admin \ PhotoController.php :

 <?php namespace Controllers\Admin; use Illuminate\Routing\Controllers\Controller; class PhotoController extends Controller { /** * Display a listing of the resource. * * @return Response */ public function index() { return 'index'; } /** * Show the form for creating a new resource. * * @return Response */ public function create() { // } /** * Store a newly created resource in storage. * * @return Response */ public function store() { // } /** * Display the specified resource. * * @return Response */ public function show($id) { return $id; } /** * Show the form for editing the specified resource. * * @return Response */ public function edit($id) { return "edit $id"; } /** * Update the specified resource in storage. * * @return Response */ public function update($id) { // } /** * Remove the specified resource from storage. * * @return Response */ public function destroy($id) { // } } 
(> (/ admin / photo GET), create (/ admin / photo / create) and save (/ admin / photo POST) actions work fine ... but don’t edit and show , I just get page status not 404.

it will work if i drop the admin root path.

Can someone tell me how I configure the Route :: resource controller to work with a nested path like admin / photo

+4
laravel laravel-4
source share
4 answers

See https://github.com/laravel/framework/issues/170 Found my answer there (see What Taylor wrote)

For those who want to see my code that now works in routes.php:

 Route::group(array('prefix' => 'admin'), function() { // Responds to Request::root() . '/admin/photo' Route::resource('photo', 'Controllers\\Admin\\PhotoController'); }); 
+15
source share

In fact, you should replace "admin / photo" with "admin.photo" for laravel to configure the resource for the photo, which is the subordinate administrator.

Check it out https://tutsplus.com/lesson/nested-resources/

+1
source share

You will probably need to say that Composer will reload the classes again, run from the command line:

 composer dump-autoload 

That should work.

0
source share

Just use the group prefix -> admin. Using the nested admin.photo will create the wrong URL for you, for example admin / {admin} / photo / {photo}, which you do not need.

0
source share

All Articles