php-grape / grape-entity

A simple facade for managing the relationship between your model and API.
MIT License
2 stars 0 forks source link

Exposing a NULL value not working #1

Closed adrienpntl closed 2 years ago

adrienpntl commented 2 years ago

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');
        });
    }
php-grape commented 2 years ago

This comes from php 8: https://github.com/wintercms/winter/issues/207

Will think about a workaround soon

adrienpntl commented 2 years ago

:+1: nice to hear that :) Thx

php-grape commented 2 years ago

Fixed with v1.0.1