Skip to content

Commit f8cb323

Browse files
committed
Merge remote-tracking branch 'scs-ben/master'
2 parents ba85bef + 08f2ef3 commit f8cb323

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/Controllers/BinshopsCategoryAdminController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ public function update_category(UpdateBinshopsBlogCategoryRequest $request, $cat
167167
)->first();
168168
$category->fill($request->all());
169169
$translation->fill($request->all());
170+
171+
// if the parent_id is passed in as 0 it will create an error
172+
if ($category->parent_id <= 0) {
173+
$category->parent_id = null;
174+
}
175+
170176
$category->save();
171177
$translation->save();
172178

src/Controllers/BinshopsReaderController.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,18 @@ public function index($locale, Request $request, $category_slug = null)
4747
if ($category_slug) {
4848
$category = BinshopsCategoryTranslation::where("slug", $category_slug)->with('category')->firstOrFail()->category;
4949
$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){
5151
$query->where("lang_id" , '=' , $request->get("lang_id"));
5252
}
53-
])->paginate(config("binshopsblog.per_page", 10));
53+
])->get();
5454

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));
6062

6163
// at the moment we handle this special case (viewing a category) by hard coding in the following two lines.
6264
// You can easily override this in the view files.

0 commit comments

Comments
 (0)