|
5 | 5 | use App\Http\Controllers\Controller;
|
6 | 6 | use Carbon\Carbon;
|
7 | 7 | use HessamCMS\Laravel\Fulltext\Search;
|
| 8 | +use HessamCMS\Models\HessamCategoryTranslation; |
8 | 9 | use Illuminate\Http\Request;
|
9 | 10 | use HessamCMS\Captcha\UsesCaptcha;
|
10 | 11 | use HessamCMS\Middleware\DetectLanguage;
|
@@ -42,32 +43,34 @@ public function index($locale, $category_slug = null, Request $request)
|
42 | 43 | $title = 'Blog Page'; // default title...
|
43 | 44 |
|
44 | 45 | $categoryChain = null;
|
| 46 | + $posts = array(); |
45 | 47 | if ($category_slug) {
|
46 |
| - $category = HessamCategory::where("slug", $category_slug)->firstOrFail(); |
| 48 | + $category = HessamCategoryTranslation::where("slug", $category_slug)->with('category')->firstOrFail()->category; |
47 | 49 | $categoryChain = $category->getAncestorsAndSelf();
|
48 |
| - $posts = $category->posts()->where("blog_etc_post_categories.blog_etc_category_id", $category->id); |
| 50 | + $posts_1 = $category->posts()->where("hessam_post_categories.category_id", $category->id)->with([ 'postTranslations' => function($query) use ($request){ |
| 51 | + $query->where("lang_id" , '=' , $request->get("lang_id")); |
| 52 | + } |
| 53 | + ])->paginate(config("hessamcms.per_page", 10)); |
| 54 | + |
| 55 | + foreach ($posts_1 as $post) { |
| 56 | + $trans = $post->postTranslations[0]; |
| 57 | + $trans->post = $post; |
| 58 | + array_push($posts, $trans); |
| 59 | + } |
49 | 60 |
|
50 | 61 | // at the moment we handle this special case (viewing a category) by hard coding in the following two lines.
|
51 | 62 | // You can easily override this in the view files.
|
52 | 63 | \View::share('hessamcms_category', $category); // so the view can say "You are viewing $CATEGORYNAME category posts"
|
53 | 64 | $title = 'Posts in ' . $category->category_name . " category"; // hardcode title here...
|
54 | 65 | } else {
|
55 |
| - $posts = HessamPostTranslation::query(); |
| 66 | + $posts = HessamPostTranslation::where('lang_id', $request->get("lang_id")) |
| 67 | + ->with(['post' => function($query){ |
| 68 | + $query->where("is_published" , '=' , true); |
| 69 | + $query->where('posted_at', '<', Carbon::now()->format('Y-m-d H:i:s')); |
| 70 | + $query->orderBy("posted_at", "desc"); |
| 71 | + }])->paginate(config("hessamcms.per_page", 10)); |
56 | 72 | }
|
57 | 73 |
|
58 |
| -// $posts = $posts->where('is_published', '=', 1) |
59 |
| -// ->where('posted_at', '<', Carbon::now()->format('Y-m-d H:i:s')) |
60 |
| -// ->where('lang_id', $request->get("lang_id")) |
61 |
| -// ->orderBy("posted_at", "desc") |
62 |
| -// ->paginate(config("hessamcms.per_page", 10)); |
63 |
| - |
64 |
| - $posts = HessamPostTranslation::where('lang_id', $request->get("lang_id")) |
65 |
| - ->with(['post' => function($query){ |
66 |
| - $query->where("is_published" , '=' , true); |
67 |
| - $query->where('posted_at', '<', Carbon::now()->format('Y-m-d H:i:s')); |
68 |
| - $query->orderBy("posted_at", "desc"); |
69 |
| - }])->paginate(config("hessamcms.per_page", 10)); |
70 |
| - |
71 | 74 | //load category hierarchy
|
72 | 75 | $rootList = HessamCategory::roots()->get();
|
73 | 76 | HessamCategory::loadSiblingsWithList($rootList);
|
@@ -121,10 +124,10 @@ public function search(Request $request)
|
121 | 124 | * @param $category_slug
|
122 | 125 | * @return mixed
|
123 | 126 | */
|
124 |
| - public function view_category($hierarchy) |
| 127 | + public function view_category($locale, $hierarchy, Request $request) |
125 | 128 | {
|
126 | 129 | $categories = explode('/', $hierarchy);
|
127 |
| - return $this->index(end($categories)); |
| 130 | + return $this->index($locale, end($categories), $request); |
128 | 131 | }
|
129 | 132 |
|
130 | 133 | /**
|
|
0 commit comments