laravel中的api.php具体是干什么的,里面应该写什么,和web.php有什么区别
微信里点“发现”,扫一下
二维码便可将本文分享至朋友圈。
api 负责注册 api 路由,web 负责传统路由
个人理解:随着项目越来越大,我们需要的定义的路由越来越多,只是按照习惯拆分了下。
看下文件 RouteServiceProvider
RouteServiceProvider
protected function mapWebRoutes() { Route::middleware('web') ->namespace($this->namespace) ->group(base_path('routes/web.php')); } protected function mapApiRoutes() { Route::prefix('api') ->middleware('api') ->namespace($this->namespace) ->group(base_path('routes/api.php')); }