ardent
ardent copied to clipboard
Ardent, Laravel 4.1 and _token - MassAssignmentException
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.
+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');
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');
@TranceGeniK Your suggestion worked perfectly for me, so thanks for that =]
Same issue with Laravel 5.1. Temp fix using $guarded attribute.