Skip to content

Update Plugin.php#35

Closed
TimFoerster wants to merge 1 commit intorainlab:masterfrom
TimFoerster:patch-1
Closed

Update Plugin.php#35
TimFoerster wants to merge 1 commit intorainlab:masterfrom
TimFoerster:patch-1

Conversation

@TimFoerster
Copy link
Copy Markdown

fixes #34

@bennothommo
Copy link
Copy Markdown

@TimFoerster thanks for this fix, however, I think the issue actually lies with the Location plugin. This plugin makes the User model use the LocationModel behavior, as seen here. This behavior is supposed to already make the state_id and country_id fillable, as this code block shows. I suspect that something is preventing this from running.

@TimFoerster
Copy link
Copy Markdown
Author

TimFoerster commented May 1, 2020

https://github.com/octobercms/library/blob/b2907902f5a3b121a291f1ba0d045461e4d6fb55/src/Auth/Models/User.php#L58
is setting a guarded field
https://github.com/rainlab/location-plugin/blob/master/behaviors/LocationModel.php#L33-L42
does not set the values, because:

The only case that is not supported is if the developer overrides both $fillable and $guarded. This seems acceptable to me, since the docs explicitly state:

Of course, you should use either $fillable or $guarded - not both

rainlab/location-plugin#53

So the rainlab.User plugin implement guarded and fillable ...

Related (old) issue:
rainlab/user-plugin#33

So either set $guaded = ['*'] or $guarded = [] in the user model.

@bennothommo
Copy link
Copy Markdown

bennothommo commented May 1, 2020

@TimFoerster you're correct. So, the issue is:

  • The October\Rain\Auth\Models\User class defines a $guarded property, making everything except for those fields writable.
  • The RainLab\User\Models\User classes, which extends the model above, then defines a $fillable property, which reverses this and makes only those fields writable.
  • The RainLab\Location\Behaviors\LocationModel class only makes the required state/country fields fillable if $guarded is set to ['*'].

So the simple fix would be to set $guarded to ['*'] in the RainLab\User\Models\User class, as this is already implied by it setting the $fillable property anyway. Would you care to submit a PR with that to the User plugin?

@TimFoerster
Copy link
Copy Markdown
Author

rainlab/user-plugin#434

@bennothommo
Copy link
Copy Markdown

Closing in favour of rainlab/user-plugin#434.

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

Successfully merging this pull request may close these issues.

Location not updating from frontend form

2 participants