0

I want to select subcategories where categories_id is 31 or 211 or 18 and where status is on and mode is also on.

I tried this but I error

    $subcategories =DB::table('subcategories')
    ->where('categories_id','31')
    ->orWhere('categories_id','211')
    ->orWhere('categories_id','18')
    ->where('status','on')
    ->where('mode','on')
    ->get();
1
  • 2
    You would probably be better of with something like ->whereIn('categories_id', [31, 211, 18]) Commented Dec 23, 2022 at 16:56

1 Answer 1

1

You have to use function:

$subcategories =DB::table('subcategories')
->where(function($query)
    {
        $query->where('categories_id', '31')
              ->orWhere('categories_id', '211')
              ->orWhere('categories_id', '18');
    })
->where('status','on')
->where('mode','on')
->get();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.