D
D
Demian12020-12-27 16:17:02
Laravel
Demian1, 2020-12-27 16:17:02

Why doesn't whereIn recognize the passed array?

Hello, tell me why when I try to filter by related models and pass an array of values, Undefined variable crashes: request

if ($request->size) {
            $productsQuery->whereHas('attributes', function($q) {
               $q->whereIn('size', $request->size);
           })->get();
        }


Although if you do this, then everything is OK
$productsQuery->whereIn('color', $request->color);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey delphinpro, 2020-12-27
@Demian1

$productsQuery->whereHas('attributes', function($q) use ($request) {
               $q->whereIn('size', $request->size);
           })->get();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question