1.2: restructure controllers to Api/ prefix and update routes
Deploy Backend / deploy (push) Has been cancelled

This commit is contained in:
parsa aghaei committed 2026-06-23 18:09:15 +03:30
1 parent c740b69675
commit 299a98d506
11 files changed
+137 -271

No files matched your search

@@ -0,0 +1,41 @@
<?php
namespace App\Http\Controllers\Api\Blog;
use App\Http\Controllers\Controller;
use App\Http\Resources\CategoryResource;
use App\Http\Resources\PostResource;
use App\Models\Blog\Category;
use App\Models\Blog\Post;
class HomeController extends Controller
{
public function index()
{
$latestPosts = Post::with(['category', 'tags', 'author'])
->orderBy('published_at', 'desc')
->take(5)
->get();
$latestCategories = Category::orderBy('created_at', 'desc')
->take(5)
->get();
$mostViewedPosts = Post::with(['category', 'tags', 'author'])
->orderBy('views', 'desc')
->take(5)
->get();
$randomPosts = Post::with(['category', 'tags', 'author'])
->inRandomOrder()
->take(4)
->get();
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);
}
}