简体   繁体   English

$fillable 不得在 Laravel 中定义(如类 Illuminate\\Database\\Eloquent\\Model)

[英]$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.其类型未定义的地方。

Mass Assignment批量分配

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.

相关问题 关系方法必须从模型调用返回一个类型为Illuminate \\ Database \\ Eloquent \\ Relations \\ Relation的对象,而不是在Laravel 4中查看 - Relationship method must return an object of type Illuminate\Database\Eloquent\Relations\Relation from model call by not view in Laravel 4 传递给 Illuminate\\Database\\Eloquent\\Relations\\HasOneOrMany::save() 的参数 1 必须是 Illuminate\\Database\\Eloquent\\Model 的实例, - Argument 1 passed to Illuminate\Database\Eloquent\Relations\HasOneOrMany::save() must be an instance of Illuminate\Database\Eloquent\Model, Cannot make non static method Illuminate\Database\Eloquent\Model::getTable() static in class App\bill, Laravel - Cannot make non static method Illuminate\Database\Eloquent\Model::getTable() static in class App\bill, Laravel laravel从模型返回中检索配置文件的名字不能将Illuminate \\ Database \\ Eloquent \\ Builder类的对象转换为字符串 - laravel retrieving profile firstname from model returns Object of class Illuminate\Database\Eloquent\Builder could not be converted to string Illuminate \\ Database \\ Eloquent \\ ModelNotFoundException-在laravel中没有模型的查询结果 - Illuminate \ Database \ Eloquent \ ModelNotFoundException - No query results for model In laravel Laravel:Model.php第2673行中的LogicException:Relationship方法必须返回类型为Illuminate \\ Database \\ Eloquent \\ Relations \\ Relation的对象 - Laravel: LogicException in Model.php line 2673: Relationship method must return an object of type Illuminate\Database\Eloquent\Relations\Relation 缺少Illuminate \\ Database \\ Eloquent \\ Model :: setAttribute()Laravel 4.1的参数2 - Missing argument 2 for Illuminate\Database\Eloquent\Model::setAttribute() Laravel 4.1 "Laravel Illuminate\\Database\\Eloquent\\Collection" - Laravel Illuminate\Database\Eloquent\Collection Laravel:类 Illuminate\\Database\\Eloquent\\Builder 的对象无法转换为字符串 - Laravel: Object of class Illuminate\Database\Eloquent\Builder could not be converted to string Object 的 class Illuminate\Database\Eloquent\Builder 无法转换为 laravel 中的字符串 8 - Object of class Illuminate\Database\Eloquent\Builder could not be converted to string in laravel 8
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM