Laravel Eloquent request with optional parameters

I am trying to find out if there is an easy way to pass a variable number of parameters to a request in Eloquent, hopefully using array.

From what I can find, there is no way to do this without wading through Inputto see what was set in the request.

Examples here: Laravel Eloquent search for two optional fields

This will work, but I don't like Laravel in its complexity / inefficiency.

This is where I am, and it may not be possible, just hoping that someone else has solved a similar problem:

$where = array("user_id" => 123, "status" => 0, "something else" => "some value");

        $orders = Order::where($where)->get()->toArray();
        return Response::json(array(
                'orders' => $orders
                ),
            200
        );

This returns an error, of course strtolower() expects parameter 1 to be string, array given.

Is it possible?

+4
source share
1

Order:: where , , , , . "" , () :

$qb = (new Order)->newQuery();
foreach ($searchParams as $k => $v) {
    $qb->where($k, $v);
}
return $qb->get(); // <-- fetch your results

, , get() :

dd(\DB::getQueryLog());

, ; Eloquent.

+5

All Articles