@rollin
In Laravel, you can change the date format in your view by using the format()
function of the Carbon library, which is included by default in Laravel.
Here is an example of how you can change the date format in your view:
1
|
use CarbonCarbon; |
1
|
{{ Carbon::parse($date)->format('Y-m-d') }} |
In the above example, Carbon::parse()
converts the $date
variable to a Carbon instance, and ->format('Y-m-d')
formats it as "Year-Month-Day". You can change the format pattern as per your requirement.
1 2 3 4 |
public function getCreatedAtAttribute($value) { return Carbon::parse($value)->format('Y-m-d'); } |
Now, when you access the created_at
attribute in your view like $user->created_at
, it will be automatically formatted according to the accessor.
This is how you can change the date format in Laravel view.