php - Laravel update controller with many inputs -


i have resource , i'm trying set update controller. in case edit form has many inputs , need update database them there might columns in database not changed edit form. have controller this:

public function update($id) {      $hostess = hostess::find($id);      $inputs=input::all();      foreach ($inputs $key => $value) {         $hostess->$key= $value;     }      if ($hostess->save())     {         return redirect::route('hostesses.show', $hostess->id);     }      return redirect::back()->withinput()->witherrors($hostess->geterrors()); } 

this gives me error because using put in view ,

 column not found: 1054 unknown column '_method' in 'field list' 

because input::all() getting hidden inputs put method. can use input::except() that, proper way of updating laravel?

you can this:

$hostess   = hostess::find($id)  $post_data = input::all(); // or $post_data = input::except('_method');  // warning untested if block below if ($hostess->update($post_data)) {     return redirect::route('hostesses.show', $hostess->id); }  return redirect::back()->withinput()->witherrors($hostess->geterrors()); 

as short update available key , value pairs.

do note have add columns $fillable property in model avoid mass assignment warning.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -