laravel 错误“strtolower() 期望参数 1 是字符串”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41329732/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 15:00:44  来源:igfitidea点击:

laravel error "strtolower() expects parameter 1 to be string"?

laravellaravel-5.3

提问by SaMeEr

I am passing json to a laravel route as following and I am runnig this query sql view.

我将 json 传递给 laravel 路由,如下所示,我正在运行这个查询 sql 视图。

{"columns":["fname","lname","mobile"], "offset":"1", "limit":"25", "order":[["fname","asc"],["lname","asc"]], "filter":[["gender","=","M"]]}

{"columns":["fname","lname","mobile"], "offset":"1", "limit":"25", "order":[["fname","asc"], ["lname","asc"]], "filter":[["gender","=","M"]]}

And this is the function placed in controller which will going to call on route

这是放置在控制器中的函数,它将在路由上调用

public function fetch_contacts(Request $request){
    if($request->header('content-type') == 'application/json' && !empty($request->header('Device')) && !empty($request->header('UID'))){
          $query = DB::connection('mysql_freesubs')->table("contact_view")
              ->select($request->columns);

              if(!empty($request->filter))
                $query = $query->where($request->filter);

              if(!empty($request->offset))
                $query = $query->offset($request->offset);

              if(!empty($request->limit))
                $query = $query->limit($request->limit);

              if(!empty($request->order))
                $query = $query->orderBy($request->order);

              $contacts = $query->get();
              return $contacts;
}

where am I going wrong ?

我哪里错了?

采纳答案by Alexey Mezenin

You're passing multidimensional array to orderBy, try this instead:

您将多维数组传递给orderBy,请尝试以下操作:

$query = $query->orderBy($request->order[0][0], $request->order[0][1]);
$query = $query->orderBy($request->order[1][0], $request->order[1][1]);