Just started using Laravel 5 and having trouble understanding how the namespace works. Example for a standard controller:
<?php namespace App\Http\Controllers;
class WelcomeController extends Controller {
I have to add \ in front of the below functions or they are not recognized:
\Validator::make();
\Redirect::back();
\Request::all();
Can you point me in the right direction as to why this is required or if i'm not thinking about this correctly anymore?
Hi RMFogarty,
That because when you are in specific namespace, here App\Http\Controllers
, you can access directly on elements on others namespaces.
If you want ton access on Validator, Lang ect you have to prefix it by .
\ is the root namespace.
To remove the \ you can just include it with the use
at the top of your class like the next example:
<?php namespace App\Http\Controllers;
use \Validator, \Redirect, \Request;
class WelcomeController extends Controller {
Validator::make();
Redirect::back();
Request::all();
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community