agaezcode
agaezcode

Reputation: 168

Composer dump-autoload in laravel seems not working

I've tried to autoload my NEW classes but it's not working. I recive an error saying that my class controller does not exist. I'm working in ubuntu env. with laravel 4.2

Composer.json

    "psr-0": {
        "Controllers": "app/",
        "Stuffs": "app/"
    }

app/Controllers/UserController.php

<?php

namespace Controllers;

use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Response;

class UserController extends BaseController
{
    public function index()
    {
        $stuffs = $this->stuffs->findAllForUser($this->user, 12);

        $this->view('user.profile', compact('stuffs'));
    }
}

app/routes.php

Route::get('user', [ 'as' => 'user.index', 'uses' => 'UserController@index' ]);

I've tried to do this to autoload those class: composer dump-autoload -o and even with sudo permission, but not working. Am I missing something? Thank you.

Upvotes: 2

Views: 1183

Answers (1)

lukasgeiter
lukasgeiter

Reputation: 152860

You have to reference the controller with the fully qualified name in your route:

Route::get('user', [ 'as' => 'user.index', 'uses' => 'Controllers\UserController@index' ]);

If you have many of those you can also use a route group to define the namespace:

Route::group(array('namespace' => 'Controllers'), function(){
    Route::get('user', [ 'as' => 'user.index', 'uses' => 'UserController@index' ]);
});

Upvotes: 2

Related Questions