Skip to content

Exposing a NULL value not working #1

@adrienpntl

Description

@adrienpntl

Exposing a field value NULL result in an error

{
  "message": "method_exists(): Argument #1 ($object_or_class) must be of type object|string, null given",
  "exception": "TypeError",
  "file": "/var/www/html/vendor/php-grape/grape-entity/src/Entity.php",
  "line": 195,

Here my code of my Entity. The field 'email_verified_at' is a timestamps, cast as Datetime in model.

    private static function initialize(): void
    {
        self::formatWith('iso_timestamp', function ($dt) {
            return $dt->format(DateTime::ISO8601);
        });

        self::expose('name');

        self::expose('email');

        self::withOptions(['format_with' => 'iso_timestamp'], function () {
            self::expose('email_verified_at');
            self::expose('created_at');
            self::expose('updated_at');
        });
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions