We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Different behaviour when casting to array an Enum implementing Arrayable class from collection and from eloquent model attribute.
I have this enum
enum Status: string implements Arrayable { case pending = 'pending'; case done = 'done'; /** * @inheritDoc */ public function toArray() { return [ 'name' => $this->name, 'value' => $this->value, 'description' => "description of {$this->name}", ]; } }
In collection:
collect(Status::pending)->toArray(); /** [ "name" => "pending", "value" => "pending", "description" => "description of pending", ] */
in Model:
class MyModel extends Model { protected $casts = [ 'status' => Status::class ]; } MyModel::first()->toArray(); /** [ 'id' => 1, 'status' => 'pending' ] */
Even without Arrayable interface on enum the result is different.
Is it right?
How can I cast MyModel to array and have enum attribute (automatically) casted following the Arrayable interface?
This is related to a (closed) PR #40605. Should it be considered for 9.x?
The text was updated successfully, but these errors were encountered:
Heya, this seems to be rejected. You can indeed always attempt a new PR for 9.x but it's up to Taylor in the end to accept or not.
Sorry, something went wrong.
No branches or pull requests
Description:
Different behaviour when casting to array an Enum implementing Arrayable class from collection and from eloquent model attribute.
Steps To Reproduce:
I have this enum
In collection:
in Model:
Even without Arrayable interface on enum the result is different.
Is it right?
How can I cast MyModel to array and have enum attribute (automatically) casted following the Arrayable interface?
This is related to a (closed) PR #40605. Should it be considered for 9.x?
The text was updated successfully, but these errors were encountered: