laravel how to update a field to a database

瘦欲@ 提交于 2019-12-13 20:46:19

问题


This is my code

$admin = Admin::find(25);
        $admin->picture = $destination;
        $admin->save();

but when I execute it, the picture field is keep NULL for example images/admin_20

the destination is a string to the location of the image.

I already tried ->update() but also nothing becomes saved.

could you help me please

Edit 1

the picture column in my database is varchar(255) utf8_unicode_ci


回答1:


Try this:

     $admin = Admin::where('id', '=', 25);
     $admin->picture = $destination;
     $admin->save();

You didn't provide much code but if it's a function

      Return $admin->picture;

EDIT

Laravel is UTF8 by default but just to make sure, check the file

 /etc/mysql/my.cnf
 collation-server = utf8_unicode_ci
 init-connect='SET NAMES utf8'
 character-set-server = utf8



回答2:


Finally I found the problem, three days working to this silly mistake

the ID column in my database should have been id



来源:https://stackoverflow.com/questions/24465200/laravel-how-to-update-a-field-to-a-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!