ardent icon indicating copy to clipboard operation
ardent copied to clipboard

Ardent, Laravel 4.1 and _token - MassAssignmentException

Open Azirius opened this issue 11 years ago • 4 comments

When attempting to save a user to the database with the $autoHydrateEntityFromInput attribute set to true, Laravel throws an exception of the MassAssignmentException kind, stating that, _token is the culprit. According to Ardent's source it appears to attempt to remove _token, however this seems to fail. I don't know if this is something to do with how Laravel 4.1 handles it's CSRF token, but unless I manually assign the model's attributes it won't allow me to store the user.

Any idea of how to circumvent this issue so I can store data while still using the CSRF protection without assigning all the form data manually?

Thanks in advance with any help in this issue.

Azirius avatar Feb 13 '14 01:02 Azirius

+1 In the meantime, i'm using the guarded attribute from eloquent in my models to prevent token to throw en exception.

protected $guarded = array('_token');

TranceGeniK avatar Apr 01 '14 17:04 TranceGeniK

Do you have autoPurgeRedundantAttributes set to true? This should remove _token and _method.

Alternatively for mass assignment you can also use fillable:

protected $fillable = array('username', 'password', 'email');

sjdaws avatar Apr 06 '14 01:04 sjdaws

@TranceGeniK Your suggestion worked perfectly for me, so thanks for that =]

Azirius avatar Apr 08 '14 09:04 Azirius

Same issue with Laravel 5.1. Temp fix using $guarded attribute.

federico77 avatar Jan 04 '16 14:01 federico77