Open mauricekindermann opened 4 days ago
Hello,
Firstly, I assume your use-case is setting a default value, which should be done via $attributes
:
protected $attributes = [
'week_starts_on' => (string) Carbon::SUNDAY,
];
Secondly, MariaDB does not support enum of integers, meaning the enum you've actually created is enum('0', '6', '1')
- see docs.
E.g. creating it via ->week_starts_on = '1'
should work.
You could also try casting the attribute as a string
via $casts
as well, which would then also support your Carbon constants usage:
protected $attributes = [
'week_starts_on' => 'string',
];
This is happening on MySQL 8.0.33 as well. The enum is created with string values in MySQL as well, hence same issue.
@Jacobs63 I think its not important to set default value from Laravel Model attributes. we can still set the default value from table schema itself. which is what am testing at the moment and the result is same. I have default set to SUNDAY i.e '0' and storing '1' from static::creating works i.e. overrides the default schema value.
Hey there, thanks for reporting this issue.
We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as one separate commit on the main/master branch and share the repository here?
Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up.
laravel new bug-report --github="--public"
Do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue.
Thanks!
Laravel Version
11.27
PHP Version
8.2
Database Driver & Version
10.5.26-MariaDB
Description
Create an enum migration
Then, in your model, try and set the value.
I tried a dozen different ways of doing this, including hard coded 0/1 values. Nothing worked
The only way I got it working was by using an integer
Steps To Reproduce
php artisan make:model CalendarSetting -m
;Then use tinker to firstOrCreate a calendar setting.
week_starts_on will always be 0, no matter what you feed into the static::creating