@@ -47,16 +47,18 @@ public function index($locale, Request $request, $category_slug = null)
47
47
if ($ category_slug ) {
48
48
$ category = BinshopsCategoryTranslation::where ("slug " , $ category_slug )->with ('category ' )->firstOrFail ()->category ;
49
49
$ categoryChain = $ category ->getAncestorsAndSelf ();
50
- $ posts_1 = $ category ->posts ()->where ("binshops_post_categories.category_id " , $ category ->id )->with ([ 'postTranslations ' => function ($ query ) use ($ request ){
50
+ $ posts = $ category ->posts ()->where ("binshops_post_categories.category_id " , $ category ->id )->with ([ 'postTranslations ' => function ($ query ) use ($ request ){
51
51
$ query ->where ("lang_id " , '= ' , $ request ->get ("lang_id " ));
52
52
}
53
- ])->paginate ( config ( " binshopsblog.per_page " , 10 ) );
53
+ ])->get ( );
54
54
55
- foreach ($ posts_1 as $ post ) {
56
- $ trans = $ post ->postTranslations [0 ];
57
- $ trans ->post = $ post ;
58
- array_push ($ posts , $ trans );
59
- }
55
+ $ posts = BinshopsPostTranslation::join ('binshops_posts ' , 'binshops_post_translations.post_id ' , '= ' , 'binshops_posts.id ' )
56
+ ->where ('lang_id ' , $ request ->get ("lang_id " ))
57
+ ->where ("is_published " , '= ' , true )
58
+ ->where ('posted_at ' , '< ' , Carbon::now ()->format ('Y-m-d H:i:s ' ))
59
+ ->orderBy ("posted_at " , "desc " )
60
+ ->whereIn ('binshops_posts.id ' , $ posts ->pluck ('id ' ))
61
+ ->paginate (config ("binshopsblog.per_page " , 10 ));
60
62
61
63
// at the moment we handle this special case (viewing a category) by hard coding in the following two lines.
62
64
// You can easily override this in the view files.
0 commit comments