gpt4 book ai didi

Laravel Forge 部署失败,用户模型上的 php 7.4 类型属性

转载 作者:行者123 更新时间:2023-12-04 10:11:49 26 4
gpt4 key购买 nike

我使用 php 7.4 在 Laravel 7 中创建了一个全新的项目,并且在 User 模型上我有以下属性:

* The attributes that are mass assignable.
*
* @var array
*/
protected array $fillable = [
'name', 'email', 'password',
];

/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected array $hidden = [
'password', 'remember_token',
];

/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected array $casts = [
'email_verified_at' => 'datetime',
];

在 Laravel Homestead 上一切正常,但是当我想在 UserSeeder 上使用 Laravel Forge 部署应用程序时,我收到了以下消息:
PHP Fatal error:  Type of App\User::$casts must not be defined (as in class Illuminate\Foundation\Auth\User)

最佳答案

您收到此错误的原因是 $casts父类中定义的属性未键入 array属性,但它在您的模型中。

根据PHP RFC: Typed Properties 2.0 :

Property types are invariant. This means that the type of a (non-private) property is not allowed to change during inheritance (this includes adding or removing property types).



为了解决这个问题,我建议简单地删除 array来自你继承的属性(property)。

我还建议阅读 this article有关类型化属性和其他 PHP 7.4 更改的更多信息。

关于Laravel Forge 部署失败,用户模型上的 php 7.4 类型属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61300879/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com