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条)

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测