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

RestfulModel::$immutableAttributes are definitely immutable #17

Open
GiacomoP opened this issue Sep 5, 2019 · 1 comment
Open

RestfulModel::$immutableAttributes are definitely immutable #17

GiacomoP opened this issue Sep 5, 2019 · 1 comment
Assignees

Comments

@GiacomoP
Copy link

GiacomoP commented Sep 5, 2019

Hello again!

I think the comment for this attribute is a bit misleading. Specifying attributes in this array will definitely make them immutable. Even updating a model via own code will throw the Exception, at least when doing a ->save(). Not sure if you meant that attributes in the array can be modified by code (like, they're not constants), but they can't be written to database.

* API routes of update and put. They can still be updated internally by Laravel, and your own code.

@specialtactics specialtactics self-assigned this Sep 24, 2019
@specialtactics
Copy link
Owner

Hey @GiacomoP

In my mind I already replied to this, but apparently not haha. So the idea of immutable is very much the same as fillable and guarded for example - it's not supposed to stop the developer from actually doing it internally (nor do I support that), it's only to stop it from happeing "automagically" by the boilerplate.

Simple use case, let's say you have a user registration, and they put in their birth date. Totally normal, and you will want that fillable. However, someone's birthday doesn't generally ever change, so you don't want them to actually update it, to prevent user abuse/getting around restrictions. So you specify to make it immutable, and the boilerplate will not allow updating it through normal patch/put.

However if you override all that logic and/or are doing something manually somewhere, sure you will need to consider your own business case - much like how laravel's fillable works (allabit slightly differently).

I will actually update the code comment and docs to make it more clear. I might rework the implementation a bit as well, as I think maybe it could be improved. For example, now it should actually prevent you from saving those changes, but it might not work in some circumstances, where the model was serialised for example.

Thanks for flagging this.

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

2 participants