Laravel Eloquent - Update() function always return true -
consider code
return user::find($user_id)->update($data_array)?true:false;
if $data_array
have columns not present in user related table. above statement return true
.
e.g: $data_array=['not_in_the_table'=>'value'];
return user::find($user_id)->update($data_array)?true:false;
returns true. condition when update returns 0
i.e. false
?
you cannot error false there because validation of laravel use library.
for laravel 4.2
public function update($user_id) { $data_array = input::all(); $validator = validator::make( $data_array, array('name' => 'required|min:5') ); if ($validator->passes()) { // success true user::find($user_id)->update($data_array) } else { //failed false } }
for more information validator hope you
Comments
Post a Comment