Laravel Eloquent - $fillable is not working? -
i have set variable $fillable in model. wanted test update functionality, , error:
sqlstate[42s22]: column not found: 1054 unknown column '_method' in 'field list' (sql: update
positionssetname= casual aquatic leader,_method= put,id= 2,description= here description,updated_at= 2014-05-29 17:05:11positions.client_id= 1 ,id= 2)"
why yelling @ _method when fillable doesn't have parameter? update function is:
client::find($client_id) ->positions() ->whereid($id) ->update(input::all());
change following:
->update(input::all()); to (exclude _method array)
->update(input::except('_method')); update:
actually following update method being called illuminate\database\eloquent\builder class being triggered _call method of illuminate\database\eloquent\relations class (because calling update on relation) , hence $fillable check not getting performed , may use input::except('_method') answered:
public function update(array $values) { return $this->query->update($this->addupdatedatcolumn($values)); } if directly call on model (not on relation):
positions::find($id)->update(input::all()); then not happen because fillable check performed within model.php because following update method called illuminate\database\eloquent\model class:
public function update(array $attributes = array()) { if ( ! $this->exists) { return $this->newquery()->update($attributes); } return $this->fill($attributes)->save(); }
Comments
Post a Comment