首先,我为我的糟糕英语道歉。
我想获得第一个 category=1
帖子,然后只有一个帖子不等于 Posts。我写的代码在下面,我的代码有错吗,或者我发送的查询不正确因为我使用 postgreSql
。
$posts= Post::where('category',1)->get();
$onlyone = Post::where('id','!=', $posts)->first();
最佳答案
这应该能让你得到你想要的......
$posts = Post::where('category', 1)->get();
$onlyone= Post::where('category', '!=', 1)->first();
如果您确实有一组要排除的帖子,您需要执行类似 Post::whereNotIn('id', $posts->pluck('id'))->first() ;
关于Laravel 我无法拉出查询结果中未包含的单行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54710366/