Skip to content

Model array cast saved as string #3306

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

Open
alanondra opened this issue Mar 5, 2025 · 1 comment
Open

Model array cast saved as string #3306

alanondra opened this issue Mar 5, 2025 · 1 comment

Comments

@alanondra
Copy link

  • Laravel-mongodb Version: 5.2.0
  • PHP Version: 8.2.27
  • Database Driver & Version: 6.0.20

Description:

Steps to reproduce

  1. Create Model with property in casts method defined as array
  2. Save Model
  3. Query Model from Collection in Studio 3T

Expected behaviour

I expected it to save as a MongoDB array.

Actual behaviour

It saved as a PHP string representation of an array.

Logs: Insert log.txt here (if necessary)
@GromNaN
Copy link
Member

GromNaN commented Mar 5, 2025

You can omit the array cast and don't apply any cast to the field. MongoDB natively stores PHP arrays as BSON Array or Document.

We could do something to modify the behavior of this cast and make it no-op.

Tracking this feature request PHPORM-305.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants