自定义路由新增改查删(curd)通用模板 
                                                    
                        
                    
                    
  
                    
                    class RouteServiceProvider extends ServiceProvider
{
    public function boot()
    {
        parent::boot();
        Route::macro("init", function ($route) {
            $this->dingo_route = $route;
        });
        Route::macro("curd", function ($controller, $except = [], $prefix = '') {
            if (!isset($this->dingo_route)) {
                throw_api_exception('请先调用`init` 实例化再调用当前方法');
            }
            !in_array('index', $except) && $this->dingo_route->get($prefix . '/index', $controller . '@index');
            !in_array('show', $except) && $this->dingo_route->get($prefix . '/show', $controller . '@show');
            !in_array('add_or_edit', $except) && $this->dingo_route->post($prefix . '/add_or_edit', $controller . '@addOrEdit');
            !in_array('delete', $except) && $this->dingo_route->post($prefix . '/delete', $controller . '@delete');
        });
    }
}
使用方法
use Illuminate\Support\Facades\Route;
//定义基于 Dingo 路由器的 API 路由
$api = app(\Dingo\Api\Routing\Router::class);
Route::init($api); //初始化,因为使用dingo
//定义 API 的版本分组,从而支持为多版本API接口,创建同样的路由以便后续回滚
$api->version('v1', ['namespace' => 'App\Http\Controllers\Api', 'domain' => Config('app.api_domain')], function ($api) {
    //常用设置
    $api->group(['prefix' => 'function/manage', 'namespace' => 'Config', 'middleware' => ['jwtauth.check:user']], function ($api) {
      Route::curd('FunctionManageController'); //重点在这里
    });
});
有空帮忙star 下项目:
github.com/huangbule2024/laravel-e...
本作品采用《CC 协议》,转载必须注明作者和本文链接
          
                    
                    
          
          
                关于 LearnKu
              
                    
                    
                    
 
推荐文章: