I'm trying to get the created_at
date of a user only but it is also fetching the time. Code:
{{{ isset(Auth::user()->created_at) ? Auth::user()->created_at : Auth::user()->email }}}
Results: 2017-05-09 11:44:09
You can get date from created_at filed in laravel using toDateString() and format() method on created_at attribute.
From Laravel 5.5 you can use now() function to get the current date and time. In blade file, you can write like this to print date.
Change date format by accessor method in model in Laravel 8Create accessor methods getCreatedAtAttribute() and getUpdatedAtAttribute() for created_at and updated_at column in model. These accessors will automatically be called by Eloquent when we retrieve the value of the created_at and updated_at attributes.
You can use toDateString()
{{ isset(Auth::user()->created_at) ? Auth::user()->created_at->toDateString() : Auth::user()->email }}
or format()
{{ isset(Auth::user()->created_at) ? Auth::user()->created_at->format('m/d/Y') : Auth::user()->email }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With