Reputation: 8661
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?
Upvotes: 0
Views: 6011
Reputation: 6393
<?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.
Upvotes: 1
Reputation: 111839
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
.
Upvotes: 1