简体   繁体   中英

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 {

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, ie MyNamespace\\BaseController .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM