Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Eloquent: multiple where() in the same column not working

Tags:

laravel

In my Database, I have column 'publish' which values are 'new', 'pending', 'running' and 'paused'. I want to make a query for 'pending' and 'running' at the same time. I use this Code but it's not working.

$q_editpost = Menu::select('id', 'bcrumb', 'heading', 'content_id', 'content_type')
        ->where('publish', 'pending')
        ->where('publish', 'running')
        ->get();

I need help!

like image 207
Md. Harun Or Rashid Avatar asked Nov 29 '16 01:11

Md. Harun Or Rashid


2 Answers

Two options, but the whereIn should be faster.

1)

$q_editpost = Menu::select('id', 'bcrumb', 'heading', 'content_id', 'content_type')
        ->whereIn('publish', ['pending', 'running'])
        ->get();

2)

$q_editpost = Menu::select('id', 'bcrumb', 'heading', 'content_id', 'content_type')
        ->where('publish', 'pending')
        ->orWhere('publish', 'running')
        ->get();
like image 153
MMMTroy Avatar answered Oct 25 '22 00:10

MMMTroy


Use whereIn for many where clouse.

$q_editpost = Menu::select('id', 'bcrumb', 'heading', 'content_id', 'content_type')
        ->whereIn('publish', ['pending', 'running'])
        ->get();
like image 42
LF00 Avatar answered Oct 25 '22 01:10

LF00