introduction 字段无法被更新
introduction
字段使用 update 方法更新失败,查看手册后发现批量操作必须定义 $fillable
属性,$fillable
属性定义了哪些字段可以被批量更新,经过测试去除 name
字段后用户名也更新失败,$fillable
属性里面应该加上 introduction
字段
<?php
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail as MustVerifyEmailContract;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Auth\MustVerifyEmail as MustVerifyEmailTrait;
class User extends Authenticatable implements MustVerifyEmailContract
{
use Notifiable, MustVerifyEmailTrait;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password', 'introduction',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}
? 后面的章节讲了这个,找了半天错误在哪????
推荐文章: