我试图忽略查询中特定类型的对象。有些类型我已禁止或删除了我不希望用户能够找到的数据。我的查询类似于:
$posts = DB::table('posts')->where('content', 'like', '%' . $request['content'] . '%')
->where('isfutured', '!=', '0')
->orderByDesc('id')->get();
但现在我也不想获取 isfutured
为 4
的数据。我怎么做?或者我可以以某种方式在 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/