Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to: mass assign an update in Laravel 4?

This is an for internal app, mass assignment security is not an issue in this case.

I'm dealing with very large (numerous) form fields, so mass assigning the user edits would be great. Mass assignment seems to work fine with 'create()' but not with doing a find & save.

This is what I have:

$post_data = Input::all(); $formobj = HugeForm::find($id); $formobj->save($post_data); 

How do I go about it? I'd rather not specify many dozens of form inputs.

like image 265
mangonights Avatar asked Jun 12 '13 22:06

mangonights


1 Answers

You should be able to use fill(array $attributes)...

$post_data = Input::all(); $formobj = HugeForm::find($id); $formobj->fill($post_data); $formobj->save(); 
like image 105
Phill Sparks Avatar answered Sep 28 '22 03:09

Phill Sparks