Laravel 路由版本 文件夹
本文作者Depapier,PHP工程师,致力于倒腾各种前沿技术,欢迎交流:
dengmuuming@163.com
0、目的
1、路由定义
app/Providers/RouteServiceProvider.php
- map()方法新增自己的路由方法,如:$this->mapChatV1();

<?php
namespace App\Providers;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider
{
protected $namespace = 'App\Http\Controllers';
public function boot()
{
parent::boot();
}
public function map()
{
$this->mapApiRoutes();
$this->mapWebRoutes();
$this->mapChatV1();
}
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'));
}
protected function mapChatV1()
{
Route::prefix('chat/v1')
->namespace($this->namespace)
->group(base_path('routes/chat/v1.php'));
}
}

2、路由实现
routes/chat/v1.php
- 创建文件routes/chat/v1.php
- 写入路由

<?php
use Illuminate\Http\Request;
Route::get('depapier', 'Test\Depapier@show');
3、控制器
app/Http/Controllers/Chat/V1/Test/Depapier.php

<?php
namespace App\Http\Controllers\Chat\V1\Test;
use App\Http\Controllers\Controller;
class Depapier extends Controller
{
public function __construct()
{
dd(123123);
die();
}
public function show()
{
dd(321);
die();
}
}
4、路由访问
http://laraveltest.com/chat/v1/depapier

|