Laravel Illuminate\Support\Facades\Input

5.9k views Asked by At

I am new to Laravel and checking out some sample code.

In a controller I see this:

<?php

use Illuminate\Support\Facades\Input;

class RegistrationController extends \BaseController {

public function __construct()
{
    $this->beforeFilter('guest');
}

Why do I have to use the "use Illuminate\Support\Facades\Input;" ?

Cant I just use eg Input::get(); like I do in my route file?

2

There are 2 answers

0
itachi On BEST ANSWER
<?php

use Illuminate\Support\Facades\Input;

class RegistrationController extends \BaseController {

public function __construct()
{
    $this->beforeFilter('guest');
}

this controller is in global namespace. so you don't need to use use Illuminate\Support\Facades\Input; you can directly call Input::get('foo');

<?php namespace Foo; //<---- check the namespace

    use Input;

    class RegistrationController extends \BaseController {

    public function __construct()
    {
        $this->beforeFilter('guest');
    }

here you can write either, use Input or \Input::get('foo') while calling.

2
Marcin Nabiałek On

You don't have to use importing namespaces (you don't need to add use Illuminate\Support\Facades\Input;) here.

You can accesss Input facade, using Input::get('something') as long as your controller is in global namespace. Otherwise you need to use \Input::get('something') or add use Input after <?php.