通过这个我得到了一系列文章:
$unsortedArticles = $this->article->getAllCurentTranslation($language);
我在文章和优先级之间有这种关系:
public function priority()
{
return $this->hasOne('App\Models\HomepagePriority','article_id','id');
}
那么我现在如何返回一组文章,但只返回没有优先级的文章?
最佳答案
您想使用doesntHave()
。像这样的东西:
$articlesWithoutPriority = Aricle::doesntHave('priority')->get();
@Gerard Reches 针对您的情况提供的解决方案(假设 getAllCurentTranslation($language)
方法在末尾使用 ->get()
):
$unsortedArticles = $this->article()
->doesntHave('priority')
->getAllCurentTranslation($language);
关于laravel - 如何获取所有没有优先权的文章?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40892659/