Laravel 如何获得他们没有优先权的所有文章?
有了这些,我得到了一系列的文章:Laravel 如何获得他们没有优先权的所有文章?,laravel,laravel-5,laravel-5.2,Laravel,Laravel 5,Laravel 5.2,有了这些,我得到了一系列的文章: $unsortedArticles = $this->article->getAllCurentTranslation($language); 我认为条款和优先权之间存在这种关系: public function priority() { return $this->hasOne('App\Models\HomepagePriority','article_id','id'); } 那么,我现在如何返回一个文章
$unsortedArticles = $this->article->getAllCurentTranslation($language);
我认为条款和优先权之间存在这种关系:
public function priority()
{
return $this->hasOne('App\Models\HomepagePriority','article_id','id');
}
那么,我现在如何返回一个文章数组,而只返回那些没有优先级的文章???您想要使用的文章。比如:
$articlesWithoutPriority = Aricle::doesntHave('priority')->get();
@Gerard Reches为您的案例提供的解决方案(假设getAllCurentTranslation($language)
方法在末尾使用->get()
):
但是在这个$unsortedArticles=$this->article->getAllCurrentTranslation($language);,我如何使用它呢?
$unsortedArticles = $this->article()
->doesntHave('priority')
->getAllCurentTranslation($language);