orderBy('published_at', 'desc') ->take(5) ->get(); // 2. 5 دسته‌بندی آخر $latestCategories = Category::orderBy('created_at', 'desc') ->take(5) ->get(); // 3. 5 پست با بیشترین بازدید $mostViewedPosts = Post::with(['category', 'tags', 'author']) ->orderBy('views', 'desc') ->take(5) ->get(); // 4. 4 پست تصادفی $randomPosts = Post::with(['category', 'tags', 'author']) ->inRandomOrder() ->take(4) ->get(); // بازگشت به صورت JSON با استفاده از منابع (Resources) return response()->json([ 'latest_posts' => PostResource::collection($latestPosts), 'latest_categories' => CategoryResource::collection($latestCategories), 'most_viewed_posts' => PostResource::collection($mostViewedPosts), 'random_posts' => PostResource::collection($randomPosts), ], 200); } }