Unable to get database notifications created_at field converted to Carbon diffForHumans #43282
Replies: 3 comments 9 replies
-
Answered in #43315 |
Beta Was this translation helpful? Give feedback.
-
>>> User::inRandomOrder()->first()->created_at->diffForHumans()
=> "3 years ago" Looks like something is wrong on your end, because >>> Role::paginate(8)->map(function ($role) { $role->creation = $role->created_at->diffForHumans(); return $role; } );
=> Illuminate\Database\Eloquent\Collection {#5416
all: [
App\Models\Auth\Role {#5374
id: 1,
name: "public",
guard_name: "web",
created_at: "2020-03-09 21:24:43",
updated_at: "2020-03-09 21:24:43",
creation: "2 years ago",
},
App\Models\Auth\Role {#5403
id: 2,
name: "standard",
guard_name: "web",
created_at: "2020-03-09 21:24:43",
updated_at: "2020-03-09 21:24:43",
creation: "2 years ago",
},
// [...] The only thing I can imagine is that, for some reason, the >>> $n = Notification::inRandomOrder()->first()
>>> $n->created_at Just to see what it gives you? If you don't have access to Tinker, just put this in a
Does that return |
Beta Was this translation helpful? Give feedback.
-
The way it looks to me is that you don't have a list called What happens if you If that still doesn't work, edit your notification Vue component to |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
We have an application running in production and displaying notifications as well. We have implemented this functionality using Laravel Notifications. As part of this implementation we are storing the notifications registry in database table named notifications, and it's working.
Currently we are unable to display the notifications sent date using some Carbon feature such as $notf->created_at->diffForHumans().
Note that we created a vuejs component that is responsible for showing the unreaded notifications. But we are stuck in this part as we can't format the created_at field to something like:
'4 days ago' instead of 2022-07-15 11:39:23.
Show notifications list
Notification class
Database registry
Current implementation
Also tried this way but the notifications does not appear
Any help is welcome.
Beta Was this translation helpful? Give feedback.
All reactions