Show post authors and action buttons

This commit is contained in:
Micha
2026-01-11 01:54:45 +01:00
parent c8d2bd508e
commit bbbf8eb6c1
5 changed files with 62 additions and 7 deletions

View File

@@ -11,7 +11,7 @@ class PostController extends Controller
{
public function index(Request $request): JsonResponse
{
$query = Post::query()->withoutTrashed();
$query = Post::query()->withoutTrashed()->with('user');
$threadParam = $request->query('thread');
if (is_string($threadParam)) {
@@ -45,6 +45,8 @@ class PostController extends Controller
'body' => $data['body'],
]);
$post->loadMissing('user');
return response()->json($this->serializePost($post), 201);
}
@@ -81,6 +83,7 @@ class PostController extends Controller
'body' => $post->body,
'thread' => "/api/threads/{$post->thread_id}",
'user_id' => $post->user_id,
'user_name' => $post->user?->name,
'created_at' => $post->created_at?->toIso8601String(),
'updated_at' => $post->updated_at?->toIso8601String(),
];