I am using laravel 5.0 to create a news site with multi-language, i try to load articles from multiples categories and with distinct number of articles (4 for first section, 3 for second), the problems is typing a call for each category would make the code too long.
here is the code
//getting the categories for "noticias"
$news_cat = Category::whereHas('slugs',function($slugs){
$slugs->where('text','LIKE','%noticias%');
})
->first();
//getting the categories for "circulos-de-cooperación"
$circles_cat = Category::whereHas('slugs',function($slugs){
$slugs->where('text','LIKE','%circulos-de-cooperación%');
})
->first();
//creating the default query with common info.
$articles = Article::with(['titles' => function($titles) use($lang){
$titles->where('lang_id','=',$lang->id);
}])
->with(['descriptions' => function($descriptions) use($lang){
$descriptions->where('lang_id','=',$lang->id);
}])
->with(['slugs' => function($slugs) use($lang){
$slugs->where('lang_id','=',$lang->id);
}])
->with('images');
//getting the articles where has the selected category (this return the correct values)
$news = $articles->where('cat_id','=',$news_cat->id)
->take(4)
->get();
//getting the articles where has the selected category (this return [])
$circles = $articles->where('cat_id','=',$circles_cat->id)
->take(3)
->get();
I am new using laravel 5.0, but i have used larave 4.2, and in laravel 4.2 i could do this without problem, if i make the whole call without sectioning, it return the correct value in the second call.
how can i solve this problem?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2AHPVj1
via IFTTT
Aucun commentaire:
Enregistrer un commentaire