Laravel-medialibrary: php 7.4

Created on 19 Feb 2020  ·  8Comments  ·  Source: spatie/laravel-medialibrary

Type of Spatie\MediaLibrary\Models\Media::$casts must be array (as in class Illuminate\Database\Eloquent\Model)

Most helpful comment

Hello, is. My English very bad :(, this error message, php have require declare field casts as

Spatie\MediaLibrary\Models\Media
Need
 array $casts =[ ]
Current
$casts = []

All 8 comments

Please provide some more info, I don't know if this an error message or a suggestion or...

Hello, is. My English very bad :(, this error message, php have require declare field casts as

Spatie\MediaLibrary\Models\Media
Need
 array $casts =[ ]
Current
$casts = []

Can confirm this is happening on my development environment too running PHP 7.4, will need to explicitly declare the type in your classes specifically in \spatie\laravel-medialibrary\src\Models\Media.php.

//old
protected $casts = [''];
//new
protected array $casts = [''];

I still don't understand the problem. All tests are returning green.

I discovered why this is happening, it's all to do with when your IDE starts being too much of a smart-ass and type-declaring your class variables, and then automatically matches their supers (in which case the laravel vendor files) and then when you get stuff like Spatie packages, that arent' type defined then.... kaboom.

✌🏼

I discovered why this is happening, it's all to do with when your IDE starts being too much of a smart-ass and type-declaring your class variables, and then automatically matches their supers (in which case the laravel vendor files) and then when you get stuff like Spatie packages, that arent' type defined then.... kaboom.

✌🏼

Thanks for your work, you have to fork and work = (

I discovered why this is happening, it's all to do with when your IDE starts being too much of a smart-ass and type-declaring your class variables, and then automatically matches their supers (in which case the laravel vendor files) and then when you get stuff like Spatie packages, that arent' type defined then.... kaboom.

✌🏼

I'm getting the same error. What do you mean by IDE being too much of a smart-ass? What we can do in this case? Thanks

I have same issue :(

Was this page helpful?
0 / 5 - 0 ratings