Skip to content

AsArrayObject, AsCollection not working when the column is null #38570

@foremtehan

Description

@foremtehan
  • Laravel Version: 8.56.0
  • PHP Version: 8.*
  • Database Driver & Version: PostgresSQL

Description:

If we want to create a nested array with AsArrayObject, AsCollection on the nullable column, if the column is null we will get the error

Steps To Reproduce:

I did what taylor does in laracon:

protected $casts = [
    'permisions' => AsArrayObject::class
];

$user = User::first();

//$user->settings is null here
$user->settings['role']['name'] = 'Developer';

$user->save();

ErrorException : Undefined array key "role"

The problem is the permisions is null , it should be empty array and taylor didnt mention that on the video:

Capture

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions