php - 用户不更新 Laravel

标签 php mysql laravel eloquent

更新方法:

public function update(UserUpdateRequest $request, Users $uzytkownik)
    {
        $this->authorize('update', $uzytkownik);

        if ( $uzytkownik->update([
            'birth' => $request->birth,
            'sex' => $request->sex,
            'about' => $request->about,
        ]) )
        {
            return 1;
        }

        return 0;
    }

在此处更新页面 1 出现。就像它做的那样。 但是在 db 中什么都没有改变。

$uzytkownik 是正确的用户,并且 这是 dd($uzytkownik);

enter image description here

dd($request->birth.'---'.$request->sex.'---'.$request->about); 下面显示正确的输入

enter image description here

为什么不能正常工作?

最佳答案

根据 documentation

Mass Assignment You may also use the create method to save a new model in a single line. The inserted model instance will be returned to you from the method. However, before doing so, you will need to specify either a fillable or guarded attribute on the model, as all Eloquent models protect against mass-assignment by default.

您需要确保 $fillable$guarded 设置正确,否则更改可能不会持久。

关于php - 用户不更新 Laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45483099/

相关文章:

MySQL 8.0.12 关键效率在 MySQL Workbench 中为 0.0%

mysql - 如何将NTP时间格式存储到MySQL中

php - 如何(以及在​​哪里)在 Laravel 中注册自定义查询方法

laravel - 如何在laravel中对多个项目进行单一身份验证?

javascript - 当我只上传一次时,图像在表格中插入了两次

php - 星期几 Yii2 主动查询

php - 简单的 html DOM 如何在特定的 div 中获取 <source> 中的 src?

laravel - 我可以将 Route-Model-Binding 的解析逻辑更改为始终小写字符串键吗?

php - 使用系统分配的托管标识连接到 Azure 存储 Blob 的 Azure PHP Web 应用程序

php - 替换所有字符直到反斜杠n次