laravel
laravel copied to clipboard
Time field as Date field
Hi guys, I have an error with my generated models, when my table has a field in type "Time" it is understanding as type "Date" and when I go to run the model it returns me the following error:
"Unexpected data found. Unexpected data found. Data missing"
I think you might be able to fix it by overriding the $casts attribute (if you've enabled base_files). Pull requests are always welcomed and encouraged to fix bugs.
Hi,
with
'casts' => [ 'json' => 'json', 'heure' => 'time'
I get
protected $casts = [ 'heure_debut_matin' => 'time',
but I still have
protected $dates = [ 'heure_debut_matin',
and "Unexpected data found. Unexpected data found. Data missing"
If you enable "base files", you'll get two files looking something similar to:
// One being the base model which will be replaced with updates every time you run `php artisan code:models`
// app/Models/Base/Movie.php
class Movie {
protected $casts = [
'showtime' => 'time',
// ...
];
protected $dates = [
'showtime',
// ...
];
}
// And another one which you can modify at will and won't be overridden by `php artisan code:models`
// Whenever you need a Movie model, you should use this one instead of the base model
// app/Models/Movie.php
class Movie extends Base\Movie {
// So, if you need to, you can just override the $dates property to look like this and get the desired effect
protected $dates = [];
}
What I'm suggesting is a workaround, though. The parser should be updated, so that this behaviour would be handled gracefully by default. However, a PR is needed.