-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
$table->enum() fails with model events like booted() static::creating #53698
Comments
Hello, Firstly, I assume your use-case is setting a default value, which should be done via protected $attributes = [
'week_starts_on' => (string) Carbon::SUNDAY,
]; Secondly, MariaDB does not support enum of integers, meaning the enum you've actually created is E.g. creating it via You could also try casting the attribute as a 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.
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! |
You're, however, ignoring one important thing - setting it just on the database does not mean the model will have the Only after refreshing/retrieving the model from database will the attribute be set on the model. E.g.: $model = Model::query()->create(); Will mean $model->week_starts_on === null // true |
Hey there, We're closing this issue because it's inactive, already solved, old, or not relevant anymore. Feel free to open up a new issue if you're still experiencing this problem. |
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
The text was updated successfully, but these errors were encountered: