Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel BaseController vs \BaseController

The default HomeController class is defined using

class HomeController extends BaseController {

However, when a resource controller is created via artisan, the class extends \BaseController instead of BaseController. Why is this, and what is the difference?

class TestResourceController extends \BaseController {
like image 725
Nyxynyx Avatar asked Jul 27 '13 01:07

Nyxynyx


1 Answers

There is no difference (in a default installation). The \ simply tells PHP to use the root namespace instead of any other class with the same name but on a different namespace. If you were to create your own class called BaseController, PHP would not know which class to use unless it were explicity defined by the namespace, i.e. MyNamespace\BaseController.

like image 160
Slickrick12 Avatar answered Oct 06 '22 00:10

Slickrick12