Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

monstajamss's avatar

Format Laravel Updated At Date

Usually laravel updated at date is in this format 2022-03-24T15:36:48.000000Z how can i pass it to my nuxtjs like this 2022/03/24 at 10:47

In my NuxtJs i am displaying it like this

{{ post.updated_at }}

In my controller i have

public function index()
    {
        $posts = Post::orderBy('created_at', 'desc')->paginate(10);

        return response()->json($posts);
    }
0 likes
3 replies
monstajamss's avatar

@Sinnbeck So i was able to do this

public function index()
    {
        $posts = Post::orderBy('created_at', 'desc')->paginate(10)->through(fn($post) =>[
            'id' => $post->id,
            'title' => $post->title,
            'body' => $post->body,
            'excerpt' => $post->excerpt,
            'updated_at' => $post->updated_at->format('Y/m/d H:i'),
        ]);

        return response()->json($posts);
    }

Which works

Sinnbeck's avatar

@monstajamss kinda like an inline api resource that's not reusable. Works but personally I would prefer a class. Kinda like inline validation vs a form request class

Please or to participate in this conversation.