[英]$fillable must not be defined (as in class Illuminate\Database\Eloquent\Model) in laravel
I have following laravel model.我有以下 Laravel 模型。 When I try to visit the site it shows the following error.
当我尝试访问该站点时,它显示以下错误。
Symfony\\Component\\ErrorHandler\\Error\\FatalError Type of App\\Models\\Setting::$fillable must not be defined (as in class Illuminate\\Database\\Eloquent\\Model)
Symfony\\Component\\ErrorHandler\\Error\\FatalError Type of App\\Models\\Setting::$fillable 不得定义(如类 Illuminate\\Database\\Eloquent\\Model)
Environment information环境信息
Laravel version: 8.60.0 Laravel 版本:8.60.0
PHP version: 7.4.16 PHP 版本:7.4.16
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Setting extends Model
{
use HasFactory;
protected array $fillable = [
'key',
'value',
];
protected $casts = [
'value' => 'array',
];
}
The error message is telling you that the ... " Type of App\\Models\\Setting::$fillable must not be defined ".错误消息告诉您...“不得定义 App\\Models\\Setting::$fillable 类型”。 So change:
所以改变:
protected array $fillable = [
'key',
'value',
];
to到
protected $fillable = [
'key',
'value',
];
where its type is not defined.其类型未定义的地方。
I encounter the same problem, on local, it ask for array and on live, it asks not to put it there.我遇到了同样的问题,在本地,它要求数组,而在现场,它要求不要把它放在那里。 Same environments on both machines.
两台机器上的环境相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.