I try to use $casts to change date format in my Model :
protected $casts = [
'created_at' => 'datetime:Y-m-d H:i',
'updated_at' => 'datetime:Y-m-d H:i'
];
It works when I retrieve the data with Eloquent :
$clients = Client::all();
return $clients;
but it doesn't with Query Builder !
$clients = DB::table('clients')->get();
return $clients;
In query builder you are using DB::table it does not use Laravel Model and you are writing this casts code to your Laravel Model. It obviously never work. They are apples and oranges.
If you use casts code, Laravel only runs this code when you get the model and use this field. Before that it does not change the values.
What are you trying to achieve there? If you give us more detailed code I will help you.