Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MYSQL query for Where clause with OR & AND in LARAVEL

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();

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading