-
Notifications
You must be signed in to change notification settings - Fork 135
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
Determine eloquent attribute type from casts #345
Determine eloquent attribute type from casts #345
Conversation
@@ -89,15 +86,53 @@ private function getBaseAttributeType(Model $model, string $key, array $value) | |||
default => new UnknownType("unimplemented DB column type [$type[0]]"), | |||
}; | |||
|
|||
if ($value['cast'] && function_exists('enum_exists') && enum_exists($value['cast'])) { | |||
if (! isset($value['cast']::cases()[0]->value)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this check is for backed enums, but might not be necessary as Laravel supports both.
@@ -89,15 +86,53 @@ private function getBaseAttributeType(Model $model, string $key, array $value) | |||
default => new UnknownType("unimplemented DB column type [$type[0]]"), | |||
}; | |||
|
|||
if ($value['cast'] && function_exists('enum_exists') && enum_exists($value['cast'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With PHP 8.1 being the min version now, function_exists('enum_exists')
check is not required anymore
@kburton-dev what a great work! Thank you so much for your time, I appreciate it! |
As mentioned in this discussion, the schema types differ slightly when generating the OpenAPI json, if using different databases, such as MySQL and SQLite.
This is to be expected if the idea is to rely on the DB schema alone to generate the API schema from Eloquent models.
This PR aims to add support for the various model casts that Laravel provides.