Level 50
from the documentation: https://laravel.com/docs/8.x/eloquent-mutators#attribute-casting
Attributes that are null will not be cast. In addition, you should never define a cast (or an attribute) that has the same name as a relationship.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a column in my table which is :
$table->json('tags')->nullable()
protected $casts = [
'tags' => 'array',
];
But when the record is null it doesnt cast to empty array why ?
from the documentation: https://laravel.com/docs/8.x/eloquent-mutators#attribute-casting
Attributes that are null will not be cast. In addition, you should never define a cast (or an attribute) that has the same name as a relationship.
Please or to participate in this conversation.