php - Laravel 忽略查询中的多种类型的对象

标签 php mysql laravel eloquent filtering

我试图忽略查询中特定类型的对象。有些类型我已禁止或删除了我不希望用户能够找到的数据。我的查询类似于:

$posts = DB::table('posts')->where('content', 'like', '%' . $request['content'] . '%')
        ->where('isfutured', '!=', '0')
        ->orderByDesc('id')->get();

但现在我也不想获取 isfutured4 的数据。我怎么做?或者我可以以某种方式在 Post 模型中阻止这些并执行我的常规 Eloquent 查询吗?

最佳答案

using query builder for multiple condition used whereIn or whereNotIn

$isfutured = [0,4]; // add in array which did not want to get 

$posts = DB::table('posts')->where('content', 'like', '%' . $request['content'] . '%')
        ->whereNotIn('isfutured', $isfutured)
        ->orderByDesc('id')->get();

using elequent

$posts = Post::whereNotIn('isfutured', $isfutured)->where('content', 'like', '%' . $request['content'] . '%')->orderByDesc('id')->get();

关于php - Laravel 忽略查询中的多种类型的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52689321/

相关文章:

PHP Post 变量有重复的、已修改的数据

MySQL 不适用于 Laravel

php - 连接表上的 ORDER BY

php - 如何取回我的 Laravel 哈希密码?

php - 在 laravel 5 的 .env 文件中哪里插入 SES key 、 secret 、SMTP 用户名、SMTP 密码?

php - 密码重置表列名称覆盖 laravel 5

php - 两个期间之间的标记逻辑

php - 使用.htaccess阻止通过/public/目录访问Laravel

php - 让变量在大括号之外工作

mysql - 在 MySQL 查询中一起使用 DISTINCT 和 COUNT