02创建laravel5.8前后台api项目--路由区分

在routes目录下新建后台路由routes/api/backend.php前台路由routes/api/frontend.php

修改app/Providers/RouteServiceProvider.php代码,目的将欢迎首页访问地址由http://your_host变成http://your_host/web。将api访问地址由http://your_host/api修改为http://your_host

/**
     * Define the "web" routes for the application.
     *
     * These routes all receive session state, CSRF protection, etc.
     *
     * @return void
     */
    protected function mapWebRoutes()
    {
        Route::prefix('web')
             ->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::middleware('api')
             ->namespace($this->namespace)
             ->group(base_path('routes/api.php'));
    }

routes/api.php 代码修改为

<?php

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::prefix('frontend')->group(function () {

    require_once __DIR__."/api/frontend.php";
});


Route::prefix('backend')->group(function () {

    require_once __DIR__."/api/backend.php";
});

routes/api/backend.php 代码修改为

<?php

Route::get('donkey', function(){
    return "hello donkey".PHP_EOL;;
});

routes/api/frontend.php 代码修改为

<?php

Route::get('lion', function(){
    return "hello lion".PHP_EOL;;
});

演示效果如下:

 

源代码地址:https://github.com/windawake/laravel-repository-pratice/tree/master

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值