It is more explicit as update returns the same 0 for a non-existent user and a if the user details already where what you are trying to set it to. So for you it might be better to first check if the user exists with either a User::findOrFail($id) or just check the return of User::find($id) and then if the user exists you do your conditional update on the returned $user. consumer Consumer::join ( 'stores', 'consumers.postal', '', 'stores.postal' ) ->where ( 'storeNumber', '', '' )->first () storeNumber consumer ->stores. Run the same query again and you will notice it returns 0 affected rows as the name is already Testing > $retval = DB::table('users')->where('id', 1)->update() ![]() > $retval = DB::table('users')->where('id', 1)->update() This strategy won't return the updated name this will only return the data before update as you use find method before update. Its so wrong, but its so Zonda If you dont want it to throw an error. ![]() Useful side note, play with php artisan tinker, ie. In 5.4 you can: updatedUser tap(User::findOrFail(1))->update(data)->fresh(). Eloquent Update Method return model Issue 13488 laravel/framework GitHub. Laravel Inertia handles routing and transferring data between your Laravel back-end and frontend no need to build an API or maintain two sets of routes. So if you try to update the name and lastname of a user with the details it actually already contains the query will return 0. Insights New issue Laravel - update () function always return true 24775 Closed davidoskay opened this issue on 5 comments davidoskay commented on edited Laravel Version: 5.6 PHP Version: 7.2 Database Driver & Version: Mysql closed this as completed on Sign up for free to join this conversation on GitHub. Insights master laravel-tips/db-models-and-eloquent.md Go to file Cannot retrieve contributors at this time 2155 lines (1590 sloc) 62. However, for you it might also not signify an error even if a 0 was returned as it just means that no records where updated. 0 means that no records have been updated. driver Driver::find (1) driver->update ( 'name'> 'expmale' ) return driver Share. driver Driver::find (1) driver->name 'expmale' driver->save () return driver or other way. ![]() So the above will return the number of records that where updated. I think no need any model helper for that. An update query returns the number of rows that where affected by the update query.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |