Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Route to controller in subfolder not working in Laravel 4

I was updating my Laravel 3 app to Laravel 4 when I hit this problem...

Routes I have tried:

Route::get('backend/login', 'backend/UserController@login');
Route::get('backend/login', 'backend.UserController@login');
like image 563
Clifford James Avatar asked Jan 24 '13 14:01

Clifford James


2 Answers

I had a similar issue just a few hours ago and had to play a little bit with it to have it working.

Routes:

Route::group(array('prefix' => 'admin'), function() {
    Route::resource('/', 'admin\DashboardController');
});

In "controllers/admin" i put the DashboardController:

namespace admin;

use Illuminate\Support\Facades\View;

class DashboardController extends \BaseController {

    public function index()
    {
        return View::make('admin/dashboard');
    }

}

That did the trick on Laravel 4. Hope you find it useful enough. :)

like image 63
Federico Stango Avatar answered Nov 07 '22 23:11

Federico Stango


At the moment, in Laravel 4 Beta 1, you can "only ?" use namespace.

For exemple here in your controller file: app/controllers/backend/UserController.php

<?php namespace Controllers\Backend;

use Illuminate\Routing\Controllers\Controller;

class UserController extends Controller {

    // Note extends Controller and not BaseController

    // Your stuff
}
?>

So after, in file: app/routes.php :

<?php
Route::get('backend/login', 'Controllers\Backend\UserController@login');

I don't know if is the better way, but working here. Edit & dump-autoload "composer.json" seems not work actualy.

If someone can improve that, he will make my day ! :)

like image 4
Pierre Broucz Avatar answered Nov 08 '22 00:11

Pierre Broucz