1.2: restructure controllers to Api/ prefix and update routes
This commit is contained in:
1 parent
cbcccfcbf8
commit
28c7a317e5
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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user