Migrate to ssr
This commit is contained in:
38
app/Http/Controllers/API/TopicsAPIController.php
Normal file
38
app/Http/Controllers/API/TopicsAPIController.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Topic;
|
||||
use App\Http\Resources\TopicResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Http\Resources\ArticleResource;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class TopicsAPIController extends Controller
|
||||
{
|
||||
/**
|
||||
* Discover Topics
|
||||
*
|
||||
* Take Random 14 Topics from Database
|
||||
*
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return TopicResource::collection(Topic::inRandomOrder()->take(12)->get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all the articles for a given topics
|
||||
*
|
||||
* @param mixed $topic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function show(Topic $topic) : JsonResponse
|
||||
{
|
||||
return response()->json([
|
||||
'topic' => new TopicResource($topic),
|
||||
'articles' => ArticleResource::collection($topic->articles()->paginate(8))
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user