Skip to content

Resource ID of 0 causes error #445

@lindyhopchris

Description

@lindyhopchris

I just ran into this, and the issue is the first ID in a legacy database was set to 0, so this was always returning true: https://github.com/cloudcreativity/laravel-json-api/blob/develop/src/Object/IdentifiableTrait.php#L78

Fixed it for now by modifying the Schema::getId() method in my resource:

	/**
	 * @param $resource
	 *      the domain record being serialized.
	 *
	 * @return string
	 */
	public function getId( $resource ) 
	{
		$id = $resource->getRouteKey();

		if( empty( $id ) ) {
			$id = 1;
		}

		return (string) $id;
	}

Originally posted by @defunctl in #368 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions