The route to the controller in a subfolder that does not work in Laravel 4

I upgraded the Laravel 3 app to Laravel 4 when I hit this issue ...

Routes I tried:

Route::get('backend/login', 'backend/UserController@login'); Route::get('backend/login', 'backend.UserController@login'); 
+8
php laravel laravel-4 controller routes
source share
7 answers

I had a similar problem just a few hours ago, and I had to play a little with her to make it work.

Routes

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

In "controller / admin" I put the DashboardController:

 namespace admin; use Illuminate\Support\Facades\View; class DashboardController extends \BaseController { public function index() { return View::make('admin/dashboard'); } } 

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

+6
source share

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

An example 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 in the file: app / routes.php:

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

I don't know if this is the best, but it works here. Edit and dump-autoload "composer.json" do not seem to work.

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

+4
source share

If you intend to use Laravel 4, you might want to take a look at this: you can specify the namespace that will be used in the route group, as you can see here: http://www.laravel-tricks.com/tricks/route- group-namespacing

So in your example:

 Route::group(array('prefix' => 'backend', 'namespace' => 'backend'), function() { Route::get('login', 'UserController@login'); }); 

It works like a charm :)

I use it, and not bad, it helps you clear the code and more clearly. Give it a try!

+2
source share

I recommend doing

 Route::group(array('prefix' => 'backend'), function() { // Responds to Request::root() . '/backend/user' Route::resource('login', 'UserController'); }); 

see more here

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

0
source share

My Admin Controller in the application / controller directory

 class AdminController extends BaseController { /**. * @return \AdminController */ public function __construct() { } } 

Now I have a folder called admin in the controllers folder ie app / controller / admin, and I have another controller there AdminDashboardController.php

 class AdminDashboardController extends AdminController { /** * Display a listing of the resource. * * @return Response */ public function getIndex() { return View::make('admin/dashboard'); } } 

And finally my Route.php file

 Route::group(array('prefix' => 'admin'), function() { # Admin Dashboard Route::controller('/', 'AdminDashboardController'); }); 

Hope this helps .. :-)

0
source share

As explained here, with Laravel 4.1 you can specify the namespace that will be used in the route group, as you can see here: http://www.laravel-tricks.com/tricks/route-group-namespacing

I use it, and not bad, it helps you clear the code and more clearly. Give it a try!

0
source share

You can also put your backend / admin panel in a package. Fruit for thought :)

-one
source share

All Articles