Mass Assignment Error Laravel Tutorial

Lets for arguments sake say this is our database columns : username, password and finally accessLevel

With the create method you pass through an Array of post data lets take this example :

now with this approach we are not assigning input to specific fields in the database like we would using the save() approach so i can easily modify the html add a form element with the id accessLevel ( with a lucky guess or something ) and set it equal to 1 and that for instance that could resemble admin access.

With the save() method we assign exactly what we want to store where thus there cannot be a mass assignment even if post data is added to the request it will just be discarded.

If however you are not passing Input::all() to the create() method and simply passing input::only() i think it might be something with the design regarding the create method. I'm not to sure about this, but whether you pass input::all() or input::only(), the create() method still gets and array so i think it won't be able to differentiate between the 2 thus the mass assignment exception is added and $fillable or $gauderd array is needed within the model to discard unwanted post data.

This is just my thought and how i understand the subject. take it with a pinch of salt.


Just wanting to add i treat Laravel like a TV remote, i press the button and the channel changes, i'm not too concerned how the remote does what it does all i know is i get the channel i want. :) if you really want to know why i would suggest having a look at the create() method and see if you can gather why this is the case.

Раздался еще один выстрел. Пуля попала в корпус мотоцикла и рикошетом отлетела в сторону. Беккер изо всех сил старался удержаться на шоссе, не дать веспе съехать на обочину. Я должен добраться до ангара.

0 thoughts on “Mass Assignment Error Laravel Tutorial

Leave a Reply

Your email address will not be published. Required fields are marked *