Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

In Larvel 4 I'm trying to setup nested resource controllers.

in routes.php:

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

in app\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)
    {
        //
    }

}

index (/admin/photo GET), create (/admin/photo/create) and store (/admin/photo POST) actions work fine... but not edit and show, I just get a page not found 404 status.

it will work though if I drop the admin root path.

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

like image 472
Arni Gudjonsson Avatar asked Dec 05 '22 12:12

Arni Gudjonsson


1 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 works now in routes.php:

Route::group(array('prefix' => 'admin'), function() {

    // Responds to Request::root() . '/admin/photo'
    Route::resource('photo', 'Controllers\\Admin\\PhotoController');
});
like image 54
Arni Gudjonsson Avatar answered Dec 11 '22 08:12

Arni Gudjonsson