Laravel Forge Deployment fail with php 7.4 typed property on User model
I create fresh new project in Laravel 7 with php 7.4 and on User model I have this properties:
* 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',
];
and on Laravel Homestead everything works fine but when I want to deploy app with Laravel Forge on UserSeeder I got this message:
PHP Fatal error: Type of App\User::$casts must not be defined (as in class Illuminate\Foundation\Auth\User)
This fails because the parent Model class doesn't have the typed property defined. According to PHP docs the current and parent class should always match on the type.
My IDE (storm) change vendor HasAttributes trait and set array type to all properties and because of that in local everything works fine. Delete vendor, composer install and return User model to default save my day ;)