Skip to content

Include relationship withData() throw error #211

@bbprojectnet

Description

@bbprojectnet

Hi,

I have "virtual" relationship declared as:

	public function relationships($request): iterable
	{
		return [
			...iterator_to_array(parent::relationships($request)),

			$this->relation('currentCouple')->withData(fn (Patient $patient) => $patient->getCurrentCouple()),
		];
	}

in my resource class. It's works fine when i invoke alwaysShowData(), but, when i want to include this relation via include query param i get:

Relationship currentCouple does not exist on resource schema patients.

why jsonapi trying to get data from model when i declared withData()? How to make it works without alwaysShowData()?

According to https://laraveljsonapi.io/docs/2.0/resources/relationships.html#specifying-data it should works as i expected ;)

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