I can not change the date format using laravel 5.4
My model looks like this:
class Feriado extends Model{
protected $fillable = ['id', 'data', 'descricao', 'created_at', 'updated_at' ];
protected $dates = ['data'=> 'm-d-Y'];
protected $primaryKey = 'id';
protected $table = 'feriados';
}
The controller that returns the data looks like this:
public function index(){
$feriados= Feriado::all();
return response()->json(['error'=> false, 'mensagem'=> null, 'data'=> $feriados]);
}
And the return is coming like this:
{
"error":false,
"mensagem":null,
"data":[
{
"id":1,
"data":"2018-01-01 00:00:00",
"descricao":"Confraterniza\u00e7\u00e3o Universal",
"created_at":null,
"updated_at":null
},
{
"id":2,
"data":"2018-03-30 00:00:00",
"descricao":"Sexta-feira Santa",
"created_at":null,
"updated_at":null
},
{
"id":3,
"data":"2018-04-21 00:00:00",
"descricao":"Tiradentes",
"created_at":null,
"updated_at":null
},
{
"id":4,
"data":"2018-05-01 00:00:00",
"descricao":"Dia do Trabalhador",
"created_at":null,
"updated_at":null
},
{
"id":5,
"data":"2018-05-31 00:00:00",
"descricao":"Corpus Christi",
"created_at":null,
"updated_at":null
},
{
"id":6,
"data":"2018-09-07 00:00:00",
"descricao":"Independ\u00eancia do Brasil",
"created_at":null,
"updated_at":null
},
{
"id":7,
"data":"2018-10-12 00:00:00",
"descricao":"Padroeira do Brasil",
"created_at":null,
"updated_at":null
},
{
"id":8,
"data":"2018-02-11 00:00:00",
"descricao":"Finados",
"created_at":null,
"updated_at":null
},
{
"id":9,
"data":"2018-11-15 00:00:00",
"descricao":"Proclama\u00e7\u00e3o da Rep\u00fablica",
"created_at":null,
"updated_at":null
},
{
"id":10,
"data":"2018-12-25 00:00:00",
"descricao":"Natal",
"created_at":null,
"updated_at":null
}
]
}
The date is coming in 2018-12-25 00:00:00
format and in the model I'm setting another format protected $dates = ['data'=> 'm-d-Y'];
Where am I going wrong?
To display the data on the screen I'm using angularjs, and even using a {{(feriado.data| date: 'dd-MM-yyyy')}}
f filter does not display correctly.