Answer the question
In order to leave comments, you need to log in
Laravel Eloquent summarizes different requests. How to get rid?
there is a code:
$model = new \App\Item;
if($value = $request->get('value'))
$model = $model->where('title', 'like', '%'.$value.'%');
$params = $model->whereNotIn('id', $ids)->orderBy('title', 'asc')->get();
$paramschecked = $model->whereIn('id', $ids)->orderBy('title', 'asc')->get();
$query= $model->whereIn('id', $ids)->orderBy('title', 'asc')->toSql();
dd($query);
string(192) "select * from `items` where `title` like ? and `id` not in (?, ?, ?, ?, ?, ?) and `id` in (?, ?, ?, ?, ?, ?) and `id` in (?, ?, ?, ?, ?, ?) order by `title` asc, `title` asc, `title` asc"
Answer the question
In order to leave comments, you need to log in
calling$model->whereNotIn('id', $ids)
, you set the where property inside the $model object, which is taken into account when subsequently calling $model->get(). To
make two different requests, you need to use two different $model objects like this:
$model = new \App\Item;
if($value = $request->get('value'))
$model = $model->where('title', 'like', '%'.$value.'%');
$paramsecheckedModel = clone $model;
$params = $model->whereNotIn('id', $ids)->orderBy('title', 'asc')->get();
$paramschecked = $paramsecheckedModel->whereIn('id', $ids)->orderBy('title', 'asc')->get();
$query = $model->toSql();
$query2 = $paramsecheckedModel->toSql();
dd([$query, $query2]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question