douduoquan2824 2017-10-10 15:48
浏览 56
已采纳

Laravel vuejs路线

What am trying to do is to build a laravel axios routes which have query parameters that is

a sample request looks like

 axios.get("/user-management/permissions?role=" + this.role)

so the aboe generates

localhost:8000/user-management/permissions?role=admin"//role value changes

Now am stuck at setting the actual routes in the laravel routes

I have the following

Route::get('permissions/{role}', "PermissionsController@PermissionRole");

THe above route is never executed.How do i go about setting up my laravel routes to have the query string parameter

  • 写回答

2条回答 默认 最新

  • doucan957495 2017-10-10 15:50
    关注

    I think you misunderstood:

    The route Route::get('permissions/{role}', "PermissionsController@PermissionRole"); will respond to requests of the form /user-management/permissions/admin

    You don't need to specify the expected query string. You need to have this route:

    Route::get('permissions', "PermissionsController@PermissionRole");
    

    Then in your controller:

    function PermissionRole(Request $request) {
           $role= $request->get("role"); //admin ?
    }
    

    If you want to add the role as part of the URL you can do:

    Route::get('permissions/{role}', "PermissionsController@PermissionRole");
    

    Then you can access the role in the action:

    function PermissionRole(Request $request, $role) {
          //$role variable name matches the route name
    }
    

    However you can also make it mandatory by using validation:

    function PermissionRole(Request $request) {
           $this->validate($request->all(), [ 
                  "role" => "required|in:admin,user" //example
           ]);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥15 如何修改pca中的feature函数
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况