• 1-1Controller之Request


     laravel5.5版本

    //路由:

    Route::any('request1',['uses'=>'StudentController@request1']);

    //控制器中的方法:

     public function request1(Request $request)
        {
            //Controller Request 取得是url中的内容:http://laraveltest.com/request1?name=sean&sex=boy
    
            //1.取值:
            //echo $request::input("name");//取url中的name值:
            //echo $request::input('sex',"未知");//如果没有取默认值
    
            //2.判断请求中是否有该参数:
           /* if ($request::has('sex')) {
                echo $request::input('sex');
            } else {
                echo "无该参数";
            }*/
    
            //3.取出请求中所有的值:
            /*$res=$request::all();
            dd($res);*/
    
            //4.请求的类型:
            //获取请求的类型:
            //echo $request::method();
    
            //判断请求的类型:
            /*if ($request::isMethod('GET')){
                echo "YES";
            }else{
                echo "No";
            }*/
           //判断请求的类型是否是ajax请求
            //var_dump($request::ajax());
    
            //5.
            //http://laraveltest.com/student/request1?name=sean&sex=boy
            //判断请求前缀是否是student开头的。
            /*$res=$request::is('student/*');
            var_dump($res);*/
    
            //6.获取当前的url
            echo $request::url();
        }
    

      

  • 相关阅读:
    Hamming Distance(随机算法)
    Difference Between Primes
    Pet(dfs)
    29. Divide Two Integers
    28. Implement strStr()
    25. Reverse Nodes in k-Group
    24. Swap Nodes in Pairs
    23. Merge k Sorted Lists
    22. Generate Parentheses
    19. Remove Nth Node From End of List
  • 原文地址:https://www.cnblogs.com/yiweiyihang/p/8468663.html
Copyright © 2020-2023  润新知