laravel 没有route.php,laravel web.php 中 Route 为什么可以直接使用?

6d58ba869ac1bbc8ca2ab34fec3a6c63.png

潇湘沐

原理很简单1.首先,你注意一下/config/app.php里面/*|--------------------------------------------------------------------------|ClassAliases|--------------------------------------------------------------------------||Thisarrayofclassaliaseswillberegisteredwhenthisapplication|isstarted.However,feelfreetoregisterasmanyasyouwishas|thealiasesare"lazy"loadedsotheydon'thinderperformance.|*/'aliases'=>['Route'=>Illuminate\Support\Facades\Route::class,];2.因为有Facades,所以我们直接去看Illuminate\Support\Facades\Route::class这个类返回的内容*@methodstatic\Illuminate\Routing\Routeget(string$uri,\Closure|array|string$action)/***Gettheregisterednameofthecomponent.**@returnstring*/protectedstaticfunctiongetFacadeAccessor(){return'router';}3.那就简单了,直接去找注册为router的组件发现是在Illuminate/Routing/RoutingServiceProvider.php/***Registertherouterinstance.**@returnvoid*/protectedfunctionregisterRouter(){$this->app->singleton('router',function($app){returnnewRouter($app['events'],$app);});}4.newRouter()看到了没,很显然就会返回Illuminate/Routing/Router.php实例;是不是发现了publicfunctionget($uri,$action=null){return$this->addRoute(['GET','HEAD'],$uri,$action);}(づ ̄3 ̄)づ╭❤~请宣我!!么么问答时间我们可以确认了'router'是在Illuminate/Routing/RoutingServiceProvider.php里面的但是为什么没有配置在/config/app.php的providers里面呢答案在这里Illuminate/Foundation/Application.php注意baseserviceproviders和configuredproviders这个答案排版放不下了,放到了文章里面问答的其它问题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值