casts property is not working to change date format

126 Views Asked by At

I am trying to change date format while fetching data in this way

 protected $casts = [
        'due_date' =>  'date:d-m-Y',
     
    ];

Blade

{{$ticket->due_date}}

It is showing is like

2022-03-13
1

There are 1 best solutions below

0
On BEST ANSWER

Casts are for json serialization (json_encode($ticket)). To get the format you want in blade, use Carbon's format method.

{{ $ticket->due_date->format('d-m-Y') }}