@Snapey - I want to have it on this format Do MMM YYYY and really don't want to be installing and importing DayJS or MomentJs to format the string in my Vue component.
I have been doing this like this:
public function index() {
return Inertia::render('Homepage', [
'posts' => Post::query()
->when(Request::input('leita'), function ($query, $search) {
$query->where('title', 'like', "%{$search}%");
})
->with('tags')
->get()
->transform(function ($post) {
return [
'slug' => $post->slug,
'title' => $post->title,
'author' => $post->author,
'created_at' => Carbon::createFromFormat('Y-m-d H:i:s', $post->created_at)->locale('is_IS')->isoFormat('Do MMM YYYY'),
'content' => $post->content,
'img_url' => $post->img_url,
'tags' => $post->tags
];
}),
'filters' => Request::only(['search'])
// Ef ég bætti við ->paginate(*), þá þarf ég að gera eftir það ->withQueryString()
]);
}
But I'm not sure how I can format the date when I have my query like this:
$post = $tag->posts()->where('slug', $slug)->with('author')->with('tags')->firstOrFail();
return Inertia::render('Post', [
'post' => $post
]);