Laravel 5.3 Eloquent:同一列中的多个where()不起作用

Md.*_*hid 6 laravel

在我的数据库中,我有"发布"列,其值为"新","待定","正在运行"和"已暂停".我想同时查询"待定"和"正在运行".我使用此代码,但它不起作用.

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

我需要帮助!

MMM*_*roy 9

两个选项,但whereIn应该更快.

1)

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

2)

$q_editpost = Menu::select('id', 'bcrumb', 'heading', 'content_id', 'content_type')
        ->where('publish', 'pending')
        ->orWhere('publish', 'running')
        ->get();
Run Code Online (Sandbox Code Playgroud)


Kri*_*ofe 1

对于许多 where 循环使用 whereIn。

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