路由之路由分组(四)

作者: 寒云暮雨 | 来源:发表于2019-10-14 10:53 被阅读0次

    我们这篇文章主要讲解laravel的路由分组
    为什么要进行分组,分组的好处有很多,方便我们进行权限的控制。例如:我们希望有些页面是用户登录之后可见,那么我们就可以进行路由分组,在路由组上加上限制(例如加中间件,这个我们后面讲)
    修改我们的路由,代码如下

    Route::get('/', 'IndexController@index');
    Route::group(['middleware' => ['auth']], function () {
        Route::post('/add', 'IndexController@add');
        Route::put('/add', 'IndexController@add');
        Route::delete('/add', 'IndexController@add');
        Route::match(['get', 'post'], '/add', 'IndexController@add');
        Route::any('/add', 'IndexController@add');
    });
    
    

    执行如下命令,查看我们的路由

    php artisan route:list
    
    image.png

    laravel支持的路由方式有很多种,主要运用就是get和post,我们已经讲过,下面简单叙述一下其他请求方式

    Route::get('/', 'IndexController@index');
    Route::group(['middleware' => ['auth']], function () {
        Route::post('/add', 'IndexController@add');
        Route::put('/add', 'IndexController@add');
        Route::delete('/add', 'IndexController@add');
        Route::match(['get', 'post'], '/add', 'IndexController@add');
        Route::any('/add', 'IndexController@add');
    });
    

    delete对应delete请求
    put对应put请求
    match和any的用法类似,不同点在于match规定了对应的请求类型,any匹配任意类型
    ps:
    这篇文章,我们讲解了路由分组,同时讲解了其他请求的定义方式,在实际开发中大家根据情况实际运用。

    相关文章

      网友评论

        本文标题:路由之路由分组(四)

        本文链接:https://www.haomeiwen.com/subject/tfolmctx.html