change the date format in laravel view page

前端 未结 11 2110
-上瘾入骨i
-上瘾入骨i 2020-12-02 06:23

I want to change the date format which is fetched from database. now I got 2016-10-01{{$user->from_date}} .I want to change the format \'d-m-y\' in laravel

11条回答
  •  既然无缘
    2020-12-02 06:49

    You can check Date Mutators: https://laravel.com/docs/5.3/eloquent-mutators#date-mutators

    You need set in your User model column from_date in $dates array and then you can change format in $dateFormat

    The another option is also put this method to your User model:

    public function getFromDateAttribute($value) {
        return \Carbon\Carbon::parse($value)->format('d-m-Y');
    }
    

    and then in view if you run {{ $user->from_date }} you will be see format that you want.

提交回复
热议问题