Laravel 4 subdirectory controller not loading input class

I am new to Laravel and am having problems with subdirectories. I want to create an admin folder inside the controllers folder and so far it works. but when I try to use the Laravel Input class it says it couldn't find it.

My routes:

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

   Route::resource('/users','Admin\\UsersController');
   Route::resource('/products','Admin\\ProductsController');
   Route::resource('/categories','Admin\\CategoriesController');
   Route::resource('/orders','Admin\\OrdersController');
   Route::resource('/reviews','Admin\\ReviewsController');

});      

      

Product controller:

 <?php namespace admin;

    class ProductsController extends \BaseController {

    protected $layout = 'master';
        /**
     * Instantiate a new ProductsController instance.
     */
    public function __construct()
    {
        $this->beforeFilter('auth.admin');
    }

    /**
     * Display a listing of the resource.
     * GET /products
     *
     * @return Response
     */
    public function index()
    {
        $input = Input::all(); //here is where it finds the error

      

And autoloading composer.json:

"autoload": {

        "classmap": [
            "app/commands",
            "app/controllers/",
            "app/models",
            "app/database/migrations",
            "app/database/seeds",
            "app/tests/TestCase.php",
            "app/controllers/Admin"
        ]
    },

      

Thank!

Edit:

I also tried to use Input (and \ Input) and it returned "Class" Facade "not found" error and when I tried:

use \Illuminate\Support\Facades\Facade;
use Input;

      

It still didn't work.

Edit 2:

Now using:

use Illuminate\Support\Facades\Input;

      

and returns the same error.

Edit 3: There were changes as suggested by @ChristopherRathgeb and now it doesn't find the product model.

Answer:

After making the changes suggested by @ChristopherRathgeb and adding \ to the View and Input classes (example $input = \Input:all();

), it worked! And now to redirect to this controller with an action method, I just used action (admin \ ProductsController) and it works!

Thanks to everyone who helped!

+3


source to share


2 answers


First you can use a namespace based route group:

Route::group(['namespace'=>'admin','prefix'=> 'admin', 'before' => 'auth.admin'],function() {
   Route::resource('/users','UsersController');
   Route::resource('/products','ProductsController');
   Route::resource('/categories','CategoriesController');
   Route::resource('/orders','OrdersController');
   Route::resource('/reviews','ReviewsController');
});

      

Next, your problem with the entrance is that you need to enable the entrance facade:

Remove this:



use \Illuminate\Support\Facades\Facade;
use Input;

      

and add the following to the top of the file:

use Illuminate\Support\Facades\Input;

      

NOTE. This answer uses php 5.4 array syntax. If you are still using php 5.3 replace [] with array ().

+6


source


Import the class Input

into the namespace you are using.

<?php namespace admin;

use \Illuminate\Support\Facades\Input;

    class ProductsController extends \BaseController {
.....

      



Or call Input

from your namespace:

public function index()
{
    $input = \Illuminate\Support\Facades\Input::all(); //here is where it finds the error

      

+1


source







All Articles