SaMeEr
SaMeEr

Reputation: 381

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

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

{"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 ?

Upvotes: 1

Views: 9964

Answers (1)

Alexey Mezenin
Alexey Mezenin

Reputation: 163768

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

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

Upvotes: 1

Related Questions