[英]laravel how to update a field to a database
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
但是当我执行它时,
picture
字段保持NULL
,例如images/admin_20
the destination
is a string to the location of the image. destination
是图像位置的字符串。
I already tried ->update()
but also nothing becomes saved. 我已经尝试过
->update()
但是什么也没有保存。
could you help me please 请问你能帮帮我吗
the picture
column in my database is varchar(255) utf8_unicode_ci
我数据库中的
picture
列是varchar(255) utf8_unicode_ci
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 Laravel默认为UTF8,但要确保检查文件
/etc/mysql/my.cnf
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
Finally I found the problem, three days working to this silly mistake 终于我找到了问题,为这个愚蠢的错误工作了三天
the ID
column in my database should have been id
我数据库中的
ID
列应为id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.