Andreea Ilie
Andreea Ilie

Reputation: 65

Laravel - Builder object returned instead of Collection

I have written a query to filter my products. This is my code:

    $products = \DB::table('products')->select('*');
    foreach ($request->all() as $cat => $subCat) {
        if($subCat != '*') {
            $products->where('id', $subCat);
        }
    }
    $products->get();

However, the query returns a Builder object and I can't figure out why.

What is exactly wrong?

Thanks.

Upvotes: 1

Views: 516

Answers (1)

Niklesh Raut
Niklesh Raut

Reputation: 34914

I doubt you haven't assign value into variable, try this

$products = $products->get();

Upvotes: 1

Related Questions