Skip to content
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

Cannot fill a models attributes when using $guarded #33939

Closed
ImJacobChen opened this issue Aug 19, 2020 · 3 comments
Closed

Cannot fill a models attributes when using $guarded #33939

ImJacobChen opened this issue Aug 19, 2020 · 3 comments

Comments

@ImJacobChen
Copy link

  • Laravel Version: 7.25.0
  • PHP Version: 7.4.8
  • Database Driver & Version: SQLite & MySQL 8 (although this is non database related I believe)

Description:

During tests I create a new Model(['attr' => 'val']) for example with $guarded = ['id'].

When I inspect the model via dd($model->toArray()) the attributes that I set are not there.

If I set $fillable = ['attr'] on the model then the attributes I set will be shown.

This only starting happening for me a few days ago

Steps To Reproduce:

I created a repo containing a demo demonstrating this behaviour. You can find the steps in the README.

https://github.com/ImJacobChen/laravel-model-guarded-bug

@ahmedsayedabdelsalam
Copy link
Contributor

ahmedsayedabdelsalam commented Aug 20, 2020

regarding to this pr #33777 you have to make sure that you fill an actual column
if column is not found in the table it will be treated as guarded and you can not set it

@ImJacobChen
Copy link
Author

Ok thank you 🙂

@robbieaverill
Copy link
Contributor

I've found that this doesn't work with unit testing, and also interferes with integration tests when run in the same test suite as a unit test that tries to do this. I've proposed a fix at #39880. My workaround is to Model::unguard() everything during TestCase::setUp(), however I'd prefer to not have to do that.

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

No branches or pull requests

3 participants