Sub-workshops for controllers in Laravel 4.1

0

I want to organize my code a bit and I want to put all the controllers belonging to the administrator in a folder inside, for example:

controllers/administrador/LogingController.php

and on the route I specify it in the following way:

Route::get('administrador/login', 'administrador\LoginController@getLogin');

but I am mistaken with the error: "The administrator class \ LoginController does not exist". Probe putting the namespace to the class leaving as follows:

 <?php
 namespace administrador;
 class LoginController extends BaseController{

and no longer pulls that error but: "Class 'administrator \ BaseController' not found"

also probe with the use app \ controllers \ BaseController but keep throwing the same error, also probe adding

 app_path().'/controllers/administrador',

in the global.php and nothing, any solution?

    
asked by lHumanizado 27.02.2017 в 00:09
source

3 answers

0

I found the form, you just have to add

app_path().'/controllers/administrador',

and the name of the class is usually placed in the route without the route

Route::get('administrador/login', 'LoginController@getLogin');

    
answered by 27.02.2017 / 02:40
source
0

OPTION 1:

You delete the namespace of the class.
And you modify the file composer.json

"autoload": {
    "classmap": [
        "app/commands",
        "app/controllers",
        "app/models",
        "app/database/migrations",
        "app/database/seeds",
        "app/tests/TestCase.php",

        "app/controllers/administrador"
    ]
},

Then you execute in your console php composer.phar dump-autoload

OPTION 2:

Modify all your drivers and add a namespace
You also modify the file composer.json

"autoload": {
    "classmap": [
        "app/commands",     
        "app/models",
        "app/database/migrations",
        "app/database/seeds",
        "app/tests/TestCase.php"
    ],
    "psr-4" : {
        "App\Controllers\" : "app/controllers"
    }
},

Again you need to run in the console php composer.phar dump-autoload

Modify your directory of this:
app/controllers/administrador
to this:
app/controllers/Administrador

And on the routes you use:

Route::get('administrador/login', 'App\Controllers\Administrador\LoginController@getLogin');
    
answered by 27.02.2017 в 03:16
0

It's super easy, you do not have to play the composer.json or anything like that ... just create a new folder within Controllers, like Controllers / Backend

then in the drivers that you create inside this new folder you must add the namespace

namespace App\Controllers\Backend;

Finally on the routes you use something like

Route::get('/', 'Backend\SomeController@someMethod');

Then you tell me if it works for you.

    
answered by 01.03.2017 в 01:27