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)
Answer
The reason you're getting this error is because the $casts
property defined in the parent class isn't typed as an array
property but it is in your model.
According to the 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).
To get around this issue I would suggest simply removing array
from your inherited properties.
I would also suggest reading this article for more information on typed properties and other PHP 7.4 changes.
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS - Conditionally Load a Different Page
- → Make a Laravel collection into angular array (octobercms)
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → OctoberCMS Fileupload completely destroys my backend
- → How do I call the value from another backed page form and use it on a component in OctoberCms