关于LARAVEL学习--在APP目录下新建模块
发布于 2021-11-18 16:40 ,所属分类:软件编程学习资料



by:Follow

namespace App\Api\Bases;这是我的基础目录,如果是控制器则是:
namespace App\Api\Controllers;大家根据目录名定义包名,创建完基础目录之后,我们便开始创建我们的路由,Laravel路由一般都是放在根目录下的routes,我们复制web.php,并重新命名我们想要的路由文件名,我这里命名为apiCustom,路由规则还是跟普通路由规则一样,没什么区别,然后我们修改路由行为文件,我们先打开app\Providers下的RouteServiceProvider.php的文件,为新建的路由创建行为,代码如下:
class RouteServiceProvider extends ServiceProvider{/*** This namespace is applied to your controller routes.** In addition, it is set as the URL generator's root namespace.** @var string*/protected $namespace = 'App\Http\Controllers';//自定义路由地址【用于前端API】protected $ApiNamespace = 'App';/*** Define your route model bindings, pattern filters, etc.** @return void*/public function boot(){//parent::boot();}/*** Define the routes for the application.** @return void*/public function map(){$this->mapApiRoutes();$this->mapWebRoutes();$this->mapApiCustomRoutes();//}/*** Define the "web" routes for the application.** These routes all receive session state, CSRF protection, etc.** @return void*/protected function mapWebRoutes(){Route::middleware('web')->namespace($this->namespace)->group(base_path('routes/web.php'));}/*** Define the "api" routes for the application.** These routes are typically stateless.** @return void*/protected function mapApiRoutes(){Route::prefix('api')->middleware('api')->namespace($this->namespace)->group(base_path('routes/api.php'));}/*** 自定义路由*/protected function mapApiCustomRoutes(){Route::prefix('apiCustom')->middleware('api')->namespace($this->ApiNamespace)->group(base_path('routes/apiCustom.php'));}}
Route::group(['prefix' => 'ad'], function () {//获取广告列表Route::get('getList', 'Api\Controllers\AdController@getList');});
这里我们指向了AdController控制器下的getList方法,调用的时候路由必须是apiCustom/ad/getList。
这样我们便成功进行了自定义模块,并成功调用,今天就为大家讲到这~









![[项目实战] 2017最新laravel5+vue.js实战演练视频播放项目移动APP端+桌面端多平台](https://static.kouhao8.com/sucaidashi/xkbb/6b86a88f49754d3111cbb5925ff42cf4.jpg?x-oss-process=image/format,webp/resize,w_88/crop,w_88,h_88,g_nw)
![[项目实战] 2017最新laravel5+vue.js实战演练视频播放项目移动APP端+桌面端多平台](https://static.kouhao8.com/sucaidashi/xkbb/dff5db18cd7e626505dbc5dc7257fb03.jpg?x-oss-process=image/format,webp/resize,w_88/crop,w_88,h_88,g_nw)
![大数据VIP学习课程 之 Hadoop全集[目录+多图预览]](https://static.kouhao8.com/sucaidashi/xkbb/b364dba1a2c78a4c48253ac45aa2d605.jpg?x-oss-process=image/format,webp/resize,w_88/crop,w_88,h_88,g_nw)

![[项目实战] 2017最新laravel5+vue.js实战演练视频播放项目移动APP端+桌面端多平台](https://static.kouhao8.com/sucaidashi/xkbb/4854b868b7258be52d0678d524e7f26f.jpg?x-oss-process=image/format,webp/resize,w_88/crop,w_88,h_88,g_nw)
![[Linux] 后盾网VIP学习教程linux视频教程48集 完整版 带详细目录](https://static.kouhao8.com/sucaidashi/xkbb/cc1b4ce86c4fbfae476ee3ec77c370dd.png?x-oss-process=image/format,webp/resize,w_88/crop,w_88,h_88,g_nw)


![[C语言] 小甲鱼 快乐学系列视频教程 C++编程学习 快速入门 48讲 完整版下载地址 附带详细目录](https://static.kouhao8.com/sucaidashi/xkbb/e64d0f4b82b80d69435dd0e26fe4cdb8.jpg?x-oss-process=image/format,webp/resize,w_88/crop,w_88,h_88,g_nw)






![[人工智能] 684个视频教程 国外关于深度学习的新版视频教程 全英文+英文字幕](https://static.kouhao8.com/sucaidashi/xkbb/6c2f5bb997fa4096de60cbb0aaafb688.png?x-oss-process=image/format,webp/resize,w_88/crop,w_88,h_88,g_nw)



![[Android] 高明鑫andriod视频教程 手机端app编程开发视频学习教程 快速入门视频](https://static.kouhao8.com/sucaidashi/xkbb/cb28acf75a296921f7606d9cf47ea645.jpg?x-oss-process=image/format,webp/resize,w_88/crop,w_88,h_88,g_nw)


相关资源