code
stringlengths
31
1.39M
docstring
stringlengths
23
16.8k
func_name
stringlengths
1
126
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
166
url
stringlengths
50
220
license
stringclasses
7 values
public function withoutRelationships(): self { return $this->withRelationships([]); }
Return a new instance without relationships. @return ResourceObject
withoutRelationships
php
cloudcreativity/laravel-json-api
src/Document/ResourceObject.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/ResourceObject.php
Apache-2.0
public function getRelations(): Collection { return $this->getRelationships()->filter(function (array $relation) { return array_key_exists('data', $relation); })->map(function (array $relation) { return $relation['data']; }); }
Get the data value of all relationships. @return Collection
getRelations
php
cloudcreativity/laravel-json-api
src/Document/ResourceObject.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/ResourceObject.php
Apache-2.0
public function withMeta($meta): self { $copy = clone $this; $copy->meta = collect($meta)->all(); return $copy; }
Return a new instance with the provided meta. @param array|Collection $meta @return ResourceObject
withMeta
php
cloudcreativity/laravel-json-api
src/Document/ResourceObject.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/ResourceObject.php
Apache-2.0
public function withoutMeta(): self { return $this->withMeta([]); }
Return a new instance without meta. @return ResourceObject
withoutMeta
php
cloudcreativity/laravel-json-api
src/Document/ResourceObject.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/ResourceObject.php
Apache-2.0
public function withLinks($links): self { $copy = clone $this; $copy->links = collect($links)->all(); return $copy; }
Return a new instance with the provided links. @param $links @return ResourceObject
withLinks
php
cloudcreativity/laravel-json-api
src/Document/ResourceObject.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/ResourceObject.php
Apache-2.0
public function withoutLinks(): self { return $this->withLinks([]); }
Return a new instance without links. @return ResourceObject
withoutLinks
php
cloudcreativity/laravel-json-api
src/Document/ResourceObject.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/ResourceObject.php
Apache-2.0
public function fields(): Collection { return $this->fieldNames->values(); }
Get all the field names. @return Collection
fields
php
cloudcreativity/laravel-json-api
src/Document/ResourceObject.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/ResourceObject.php
Apache-2.0
public function get(string $field, $default = null) { return Arr::get($this->all(), $field, $default); }
Get a field value. @param string $field @param mixed $default @return mixed
get
php
cloudcreativity/laravel-json-api
src/Document/ResourceObject.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/ResourceObject.php
Apache-2.0
public function has(string ...$fields): bool { return $this->fieldNames->has($fields); }
Do the fields exist? @param string ...$fields @return bool
has
php
cloudcreativity/laravel-json-api
src/Document/ResourceObject.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/ResourceObject.php
Apache-2.0
public function forget(string ...$fields): self { $copy = clone $this; $copy->attributes = $this->getAttributes()->forget($fields)->all(); $copy->relationships = $this->getRelationships()->forget($fields)->all(); $copy->normalize(); return $copy; }
Return a new instance with the supplied attribute/relationship fields removed. @param string ...$fields @return ResourceObject
forget
php
cloudcreativity/laravel-json-api
src/Document/ResourceObject.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/ResourceObject.php
Apache-2.0
public function only(string ...$fields): self { $forget = $this->fields()->reject(function ($value) use ($fields) { return in_array($value, $fields, true); }); return $this->forget(...$forget); }
Return a new instance that only has the specified attribute/relationship fields. @param string ...$fields @return ResourceObject
only
php
cloudcreativity/laravel-json-api
src/Document/ResourceObject.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/ResourceObject.php
Apache-2.0
public function replace(string $field, $value): self { if ('type' === $field) { return $this->putIdentifier($value, $this->id); } if ('id' === $field) { return $this->putIdentifier($this->type, $value); } if ($this->isAttribute($field)) { return $this->putAttr($field, $value); } if ($this->isRelationship($field)) { return $this->putRelation($field, $value); } throw new \OutOfBoundsException("Field {$field} is not an attribute or relationship."); }
Return a new instance with a new attribute/relationship field value. The field must exist, otherwise it cannot be determined whether to replace either an attribute or a relationship. If the field is a relationship, the `data` member of that relationship will be replaced. @param string $field @param $value @return ResourceObject @throws \OutOfBoundsException if the field does not exist.
replace
php
cloudcreativity/laravel-json-api
src/Document/ResourceObject.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/ResourceObject.php
Apache-2.0
public function put(string $field, $value): self { if ($this->isRelationship($field)) { return $this->putRelation($field, $value); } return $this->putAttr($field, $value); }
Set a field. Sets the provided value as a relation if it is already defined as a relation. Otherwise, sets it as an attribute. @param string $field @param mixed|null $value @return ResourceObject
put
php
cloudcreativity/laravel-json-api
src/Document/ResourceObject.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/ResourceObject.php
Apache-2.0
public function putAttr(string $field, $value): self { $copy = clone $this; $copy->attributes[$field] = $value; $copy->normalize(); return $copy; }
Set an attribute. @param string $field @param mixed|null $value @return ResourceObject
putAttr
php
cloudcreativity/laravel-json-api
src/Document/ResourceObject.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/ResourceObject.php
Apache-2.0
public function putRelation(string $field, ?array $value): self { $copy = clone $this; $copy->relationships[$field] = $copy->relationships[$field] ?? []; $copy->relationships[$field]['data'] = $value; $copy->normalize(); return $copy; }
Set a relation. @param string $field @param array|null $value @return ResourceObject
putRelation
php
cloudcreativity/laravel-json-api
src/Document/ResourceObject.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/ResourceObject.php
Apache-2.0
public function pointer(string $key, string $prefix = ''): string { $prefix = rtrim($prefix, '/'); if ('type' === $key) { return $prefix . '/type'; } if ('id' === $key) { return $prefix . '/id'; } $parts = collect(explode('.', $key)); $field = $parts->first(); if ($this->isAttribute($field)) { return $prefix . '/attributes/' . $parts->implode('/'); } if ($this->isRelationship($field)) { $name = 1 < $parts->count() ? $field . '/' . $parts->put(0, 'data')->implode('/') : $field; return $prefix . "/relationships/{$name}"; } return $prefix ? $prefix : '/'; }
Convert a validation key to a JSON pointer. @param string $key @param string $prefix @return string
pointer
php
cloudcreativity/laravel-json-api
src/Document/ResourceObject.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/ResourceObject.php
Apache-2.0
public function pointerForRelationship(string $key, string $default = '/'): string { $field = collect(explode('.', $key))->first(); if (!$this->isRelationship($field)) { throw new \InvalidArgumentException("Field {$field} is not a relationship."); } $pointer = $this->pointer($key); return Str::after($pointer, "relationships/{$field}") ?: $default; }
Convert a validation key to a JSON pointer for a relationship object within the resource. @param string $key @param string $default @return string
pointerForRelationship
php
cloudcreativity/laravel-json-api
src/Document/ResourceObject.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/ResourceObject.php
Apache-2.0
public function all(): array { return $this->fieldValues->all(); }
Get the values of all fields. @return array
all
php
cloudcreativity/laravel-json-api
src/Document/ResourceObject.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/ResourceObject.php
Apache-2.0
private function putIdentifier(string $type, ?string $id): self { $copy = clone $this; $copy->type = $type; $copy->id = $id; $copy->normalize(); return $copy; }
@param string $type @param string|null $id @return ResourceObject
putIdentifier
php
cloudcreativity/laravel-json-api
src/Document/ResourceObject.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/ResourceObject.php
Apache-2.0
public function setMeta(?iterable $meta): self { $this->meta = collect($meta)->toArray() ?: null; return $this; }
@param iterable|null $meta @return $this
setMeta
php
cloudcreativity/laravel-json-api
src/Document/Concerns/HasMeta.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Concerns/HasMeta.php
Apache-2.0
public static function cast($value): self { if ($value instanceof self) { return $value; } if (is_array($value)) { return self::fromArray($value); } throw new UnexpectedValueException('Expecting an error object or an array.'); }
Cast a value to an error. @param Error|array $value @return Error
cast
php
cloudcreativity/laravel-json-api
src/Document/Error/Error.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Error.php
Apache-2.0
public static function fromArray(array $input): self { return new self( $input[self::ID] ?? null, $input[self::STATUS] ?? null, $input[self::CODE] ?? null, $input[self::TITLE] ?? null, $input[self::DETAIL] ?? null, $input[self::SOURCE] ?? null, $input[self::LINKS] ?? null, $input[self::META] ?? null ); }
Create an error from an array. @param array $input @return Error
fromArray
php
cloudcreativity/laravel-json-api
src/Document/Error/Error.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Error.php
Apache-2.0
public function __construct( $id = null, $status = null, ?string $code = null, ?string $title = null, ?string $detail = null, ?iterable $source = null, ?iterable $links = null, ?iterable $meta = null ) { $this->setId($id); $this->setStatus($status); $this->setCode($code); $this->setTitle($title); $this->setDetail($detail); $this->setSource($source); $this->setLinks($links); $this->setMeta($meta); }
Error constructor. @param string|int|null $id @param string|int|null $status @param string|null $code @param string|null $title @param string|null $detail @param iterable|null $source @param iterable|null $links @param iterable|null $meta
__construct
php
cloudcreativity/laravel-json-api
src/Document/Error/Error.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Error.php
Apache-2.0
public function getId() { return $this->id; }
The unique identifier for this particular occurrence of the problem. @return string|int|null
getId
php
cloudcreativity/laravel-json-api
src/Document/Error/Error.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Error.php
Apache-2.0
public function setId($id): self { if (!is_string($id) && !is_int($id) && !is_null($id)) { throw new InvalidArgumentException('Expecting a string, integer or null id.'); } $this->id = $id ?: null; return $this; }
Set a unique identifier for this particular occurrence of the problem. @param string|int|null $id @return $this
setId
php
cloudcreativity/laravel-json-api
src/Document/Error/Error.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Error.php
Apache-2.0
public function getStatus(): ?string { return $this->status; }
The HTTP status code applicable to this problem, expressed as a string value. @return string|null
getStatus
php
cloudcreativity/laravel-json-api
src/Document/Error/Error.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Error.php
Apache-2.0
public function setStatus($status): self { if (is_int($status)) { $status = (string) $status; } if (!is_string($status) && !is_null($status)) { throw new InvalidArgumentException('Expecting an integer, string or null status.'); } $this->status = $status ?: null; return $this; }
Set the HTTP status code applicable to this problem. @param string|int|null $status @return $this
setStatus
php
cloudcreativity/laravel-json-api
src/Document/Error/Error.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Error.php
Apache-2.0
public function getCode(): ?string { return $this->code; }
The application-specific error code, expressed as a string value. @return string|null
getCode
php
cloudcreativity/laravel-json-api
src/Document/Error/Error.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Error.php
Apache-2.0
public function setCode(?string $code): self { $this->code = $code; return $this; }
Set an application-specific error code. @param string|null $code @return $this
setCode
php
cloudcreativity/laravel-json-api
src/Document/Error/Error.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Error.php
Apache-2.0
public function getTitle(): ?string { return $this->title; }
A short, human-readable summary of the problem. The title SHOULD NOT change from occurrence to occurrence of the problem, except for purposes of localization. @return string|null
getTitle
php
cloudcreativity/laravel-json-api
src/Document/Error/Error.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Error.php
Apache-2.0
public function setTitle(?string $title): self { $this->title = $title; return $this; }
Set a short, human-readable summary of the problem. @param string|null $title @return $this
setTitle
php
cloudcreativity/laravel-json-api
src/Document/Error/Error.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Error.php
Apache-2.0
public function setDetail(?string $detail): self { $this->detail = $detail; return $this; }
Set a human-readable explanation specific to this occurrence of the problem. @param string|null $detail @return $this
setDetail
php
cloudcreativity/laravel-json-api
src/Document/Error/Error.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Error.php
Apache-2.0
public function getSource(): ?array { return $this->source ?: null; }
An array containing references to the source of the error. @return array|null
getSource
php
cloudcreativity/laravel-json-api
src/Document/Error/Error.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Error.php
Apache-2.0
public function setSource(?iterable $source): self { $this->source = collect($source)->toArray(); return $this; }
Set an array containing references to the source of the error. @param iterable|null $source @return $this
setSource
php
cloudcreativity/laravel-json-api
src/Document/Error/Error.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Error.php
Apache-2.0
public function setSourcePointer(?string $pointer): self { if (is_null($pointer)) { unset($this->source[self::SOURCE_POINTER]); } else { $this->source[self::SOURCE_POINTER] = $pointer; } return $this; }
Set a JSON pointer to the source of the error. A JSON Pointer [RFC6901] to the associated entity in the request document [e.g. "/data" for a primary data object, or "/data/attributes/title" for a specific attribute]. @param string|null $pointer @return $this
setSourcePointer
php
cloudcreativity/laravel-json-api
src/Document/Error/Error.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Error.php
Apache-2.0
public function setSourceParameter(?string $parameter): self { if (is_null($parameter)) { unset($this->source[self::SOURCE_PARAMETER]); } else { $this->source[self::SOURCE_PARAMETER] = $parameter; } return $this; }
Set a string indicating which URI query parameter caused the error. @param string|null $parameter @return $this
setSourceParameter
php
cloudcreativity/laravel-json-api
src/Document/Error/Error.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Error.php
Apache-2.0
public function setLink(string $key, $link): self { if (is_null($link)) { unset($this->links[$key]); } else { $this->links[$key] = Link::cast($link); } return $this; }
Set a link. @param string $key @param Link|string|array|null $link @return Error
setLink
php
cloudcreativity/laravel-json-api
src/Document/Error/Error.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Error.php
Apache-2.0
public function setAboutLink($link): self { return $this->setLink(self::LINKS_ABOUT, $link); }
Set a link that leads to further details about this particular occurrence of the problem. @param Link|string|array $link @return $this
setAboutLink
php
cloudcreativity/laravel-json-api
src/Document/Error/Error.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Error.php
Apache-2.0
public static function cast($value): self { if ($value instanceof self) { return $value; } if ($value instanceof Error) { return new self($value); } throw new \UnexpectedValueException('Expecting an errors collection or an error object.'); }
@param Errors|Error $value @return static
cast
php
cloudcreativity/laravel-json-api
src/Document/Error/Errors.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Errors.php
Apache-2.0
public function getStatus(): ?int { $statuses = collect($this->errors)->filter(function (Error $error) { return $error->hasStatus(); })->map(function (Error $error) { return (int) $error->getStatus(); })->unique(); if (2 > count($statuses)) { return $statuses->first() ?: null; } $only4xx = $statuses->every(function (int $status) { return 400 <= $status && 499 >= $status; }); return $only4xx ? Response::HTTP_BAD_REQUEST : Response::HTTP_INTERNAL_SERVER_ERROR; }
Get the most applicable HTTP status code. When a server encounters multiple problems for a single request, the most generally applicable HTTP error code SHOULD be used in the response. For instance, 400 Bad Request might be appropriate for multiple 4xx errors or 500 Internal Server Error might be appropriate for multiple 5xx errors. @return int|null @see https://jsonapi.org/format/#errors
getStatus
php
cloudcreativity/laravel-json-api
src/Document/Error/Errors.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Errors.php
Apache-2.0
public function authentication(): ErrorInterface { return new NeomerxError( null, null, null, Response::HTTP_UNAUTHORIZED, $this->trans('unauthorized', 'code'), $this->trans('unauthorized', 'title'), $this->trans('unauthorized', 'detail') ); }
Create an error for when a request is not authenticated. @return ErrorInterface
authentication
php
cloudcreativity/laravel-json-api
src/Document/Error/Translator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Translator.php
Apache-2.0
public function authorization(): ErrorInterface { return new NeomerxError( null, null, null, Response::HTTP_FORBIDDEN, $this->trans('forbidden', 'code'), $this->trans('forbidden', 'title'), $this->trans('forbidden', 'detail') ); }
Create an error for when a request is not authorized. @return ErrorInterface
authorization
php
cloudcreativity/laravel-json-api
src/Document/Error/Translator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Translator.php
Apache-2.0
public function tokenMismatch(): ErrorInterface { return new NeomerxError( null, null, null, 419, $this->trans('token_mismatch', 'code'), $this->trans('token_mismatch', 'title'), $this->trans('token_mismatch', 'detail') ); }
Create an error for a token mismatch. @return ErrorInterface
tokenMismatch
php
cloudcreativity/laravel-json-api
src/Document/Error/Translator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Translator.php
Apache-2.0
public function memberRequired(string $path, string $member): ErrorInterface { return new NeomerxError( null, null, null, Response::HTTP_BAD_REQUEST, $this->trans('member_required', 'code'), $this->trans('member_required', 'title'), $this->trans('member_required', 'detail', compact('member')), $this->pointer($path) ); }
Create an error for a member that is required. @param string $path @param string $member @return ErrorInterface
memberRequired
php
cloudcreativity/laravel-json-api
src/Document/Error/Translator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Translator.php
Apache-2.0
public function memberNotObject(string $path, string $member): ErrorInterface { return new NeomerxError( null, null, null, Response::HTTP_BAD_REQUEST, $this->trans('member_object_expected', 'code'), $this->trans('member_object_expected', 'title'), $this->trans('member_object_expected', 'detail', compact('member')), $this->pointer($path, $member) ); }
Create an error for a member that must be an object. @param string $path @param string $member @return ErrorInterface
memberNotObject
php
cloudcreativity/laravel-json-api
src/Document/Error/Translator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Translator.php
Apache-2.0
public function memberNotIdentifier(string $path, string $member): ErrorInterface { return new NeomerxError( null, null, null, Response::HTTP_BAD_REQUEST, $this->trans('member_identifier_expected', 'code'), $this->trans('member_identifier_expected', 'title'), $this->trans('member_identifier_expected', 'detail', compact('member')), $this->pointer($path, $member) ); }
Create an error for a member that must be a resource identifier. @param string $path @param string $member @return ErrorInterface
memberNotIdentifier
php
cloudcreativity/laravel-json-api
src/Document/Error/Translator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Translator.php
Apache-2.0
public function memberFieldNotAllowed(string $path, string $member, string $field): ErrorInterface { return new NeomerxError( null, null, null, Response::HTTP_BAD_REQUEST, $this->trans('member_field_not_allowed', 'code'), $this->trans('member_field_not_allowed', 'title'), $this->trans('member_field_not_allowed', 'detail', compact('member', 'field')), $this->pointer($path, $member) ); }
Create an error for when a member has a field that is not allowed. @param string $path @param string $member @param string $field @return ErrorInterface
memberFieldNotAllowed
php
cloudcreativity/laravel-json-api
src/Document/Error/Translator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Translator.php
Apache-2.0
public function memberNotString(string $path, string $member): ErrorInterface { return new NeomerxError( null, null, null, Response::HTTP_BAD_REQUEST, $this->trans('member_string_expected', 'code'), $this->trans('member_string_expected', 'title'), $this->trans('member_string_expected', 'detail', compact('member')), $this->pointer($path, $member) ); }
Create an error for a member that must be a string. @param string $path @param string $member @return ErrorInterface
memberNotString
php
cloudcreativity/laravel-json-api
src/Document/Error/Translator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Translator.php
Apache-2.0
public function memberEmpty(string $path, string $member): ErrorInterface { return new NeomerxError( null, null, null, Response::HTTP_BAD_REQUEST, $this->trans('member_empty', 'code'), $this->trans('member_empty', 'title'), $this->trans('member_empty', 'detail', compact('member')), $this->pointer($path, $member) ); }
Create an error for a member that cannot be an empty value. @param string $path @param string $member @return ErrorInterface
memberEmpty
php
cloudcreativity/laravel-json-api
src/Document/Error/Translator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Translator.php
Apache-2.0
public function resourceTypeNotSupported(string $type, string $path = '/data'): ErrorInterface { return new NeomerxError( null, null, null, Response::HTTP_CONFLICT, $this->trans('resource_type_not_supported', 'code'), $this->trans('resource_type_not_supported', 'title'), $this->trans('resource_type_not_supported', 'detail', compact('type')), $this->pointer($path, 'type') ); }
Create an error for when the resource type is not supported by the endpoint. @param string $type the resource type that is not supported. @param string $path @return ErrorInterface
resourceTypeNotSupported
php
cloudcreativity/laravel-json-api
src/Document/Error/Translator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Translator.php
Apache-2.0
public function resourceTypeNotRecognised(string $type, string $path = '/data'): ErrorInterface { return new NeomerxError( null, null, null, Response::HTTP_BAD_REQUEST, $this->trans('resource_type_not_recognised', 'code'), $this->trans('resource_type_not_recognised', 'title'), $this->trans('resource_type_not_recognised', 'detail', compact('type')), $this->pointer($path, 'type') ); }
Create an error for when a resource type is not recognised. @param string $type the resource type that is not recognised. @param string $path @return ErrorInterface
resourceTypeNotRecognised
php
cloudcreativity/laravel-json-api
src/Document/Error/Translator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Translator.php
Apache-2.0
public function resourceIdNotSupported(string $id, string $path = '/data'): ErrorInterface { return new NeomerxError( null, null, null, Response::HTTP_CONFLICT, $this->trans('resource_id_not_supported', 'code'), $this->trans('resource_id_not_supported', 'title'), $this->trans('resource_id_not_supported', 'detail', compact('id')), $this->pointer($path, 'id') ); }
Create an error for when the resource id is not supported by the endpoint. @param string $id the resource id that is not supported. @param string $path @return ErrorInterface
resourceIdNotSupported
php
cloudcreativity/laravel-json-api
src/Document/Error/Translator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Translator.php
Apache-2.0
public function resourceDoesNotSupportClientIds(string $type, string $path = '/data'): ErrorInterface { return new NeomerxError( null, null, null, Response::HTTP_FORBIDDEN, $this->trans('resource_client_ids_not_supported', 'code'), $this->trans('resource_client_ids_not_supported', 'title'), $this->trans('resource_client_ids_not_supported', 'detail', compact('type')), $this->pointer($path, 'id') ); }
Create an error for when a resource does not support client-generated ids. @param string $type @param string $path @return ErrorInterface
resourceDoesNotSupportClientIds
php
cloudcreativity/laravel-json-api
src/Document/Error/Translator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Translator.php
Apache-2.0
public function resourceExists(string $type, string $id, string $path = '/data'): ErrorInterface { return new NeomerxError( null, null, null, Response::HTTP_CONFLICT, $this->trans('resource_exists', 'code'), $this->trans('resource_exists', 'title'), $this->trans('resource_exists', 'detail', compact('type', 'id')), $this->pointer($path) ); }
Create an error for a resource already existing. @param string $type the resource type @param string $id the resource id @param string $path @return ErrorInterface
resourceExists
php
cloudcreativity/laravel-json-api
src/Document/Error/Translator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Translator.php
Apache-2.0
public function resourceDoesNotExist(string $path): ErrorInterface { return new NeomerxError( null, null, null, Response::HTTP_NOT_FOUND, $this->trans('resource_not_found', 'code'), $this->trans('resource_not_found', 'title'), $this->trans('resource_not_found', 'detail'), $this->pointer($path) ); }
Create an error for a resource identifier that does not exist. @param string $path @return ErrorInterface
resourceDoesNotExist
php
cloudcreativity/laravel-json-api
src/Document/Error/Translator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Translator.php
Apache-2.0
public function resourceFieldExistsInAttributesAndRelationships( string $field, string $path = '/data' ): ErrorInterface { return new NeomerxError( null, null, null, Response::HTTP_BAD_REQUEST, $this->trans('resource_field_exists_in_attributes_and_relationships', 'code'), $this->trans('resource_field_exists_in_attributes_and_relationships', 'title'), $this->trans('resource_field_exists_in_attributes_and_relationships', 'detail', compact('field')), $this->pointer($path) ); }
Create an error for when a resource field exists in both the attributes and relationships members. @param string $field @param string $path @return ErrorInterface
resourceFieldExistsInAttributesAndRelationships
php
cloudcreativity/laravel-json-api
src/Document/Error/Translator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Translator.php
Apache-2.0
public function resourceCannotBeDeleted(?string $detail = null): ErrorInterface { return new NeomerxError( null, null, null, Response::HTTP_UNPROCESSABLE_ENTITY, $this->trans('resource_cannot_be_deleted', 'code'), $this->trans('resource_cannot_be_deleted', 'title'), $detail ?: $this->trans('resource_cannot_be_deleted', 'detail') ); }
Create an error for when a resource cannot be deleted. @param string|null $detail @return ErrorInterface
resourceCannotBeDeleted
php
cloudcreativity/laravel-json-api
src/Document/Error/Translator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Translator.php
Apache-2.0
public function invalidResource( string $path, ?string $detail = null, array $failed = [] ): ErrorInterface { return new NeomerxError( null, null, null, Response::HTTP_UNPROCESSABLE_ENTITY, $this->trans('resource_invalid', 'code'), $this->trans('resource_invalid', 'title'), $detail ?: $this->trans('resource_invalid', 'detail'), $this->pointer($path), !empty($failed), $failed ? compact('failed') : null ); }
Create an error for an invalid resource. @param string $path @param string|null $detail the validation message (already translated). @param array $failed rule failure details @return ErrorInterface
invalidResource
php
cloudcreativity/laravel-json-api
src/Document/Error/Translator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Translator.php
Apache-2.0
public function invalidQueryParameter(string $param, ?string $detail = null, array $failed = []): ErrorInterface { return new NeomerxError( null, null, null, Response::HTTP_BAD_REQUEST, $this->trans('query_invalid', 'code'), $this->trans('query_invalid', 'title'), $detail ?: $this->trans('query_invalid', 'detail'), [NeomerxError::SOURCE_PARAMETER => $param], !empty($failed), $failed ? compact('failed') : null ); }
Create an error for an invalid query parameter. @param string $param @param string|null $detail the validation message (already translated). @param array $failed rule failure details. @return ErrorInterface
invalidQueryParameter
php
cloudcreativity/laravel-json-api
src/Document/Error/Translator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Translator.php
Apache-2.0
public function failedValidator(ValidatorContract $validator, ?Closure $closure = null): ErrorCollection { $failed = $this->doesIncludeFailed() ? $validator->failed() : []; $errors = new ErrorCollection(); foreach ($validator->errors()->messages() as $key => $messages) { $failures = $this->createValidationFailures($failed[$key] ?? []); foreach ($messages as $detail) { if ($closure) { $currentFailure = $failures->shift() ?: []; $errors->add($this->call($closure, $key, $detail, $currentFailure)); continue; } $errors->add(new NeomerxError( null, null, null, Response::HTTP_UNPROCESSABLE_ENTITY, $this->trans('failed_validator', 'code'), $this->trans('failed_validator', 'title'), $detail ?: $this->trans('failed_validator', 'detail') )); } } return $errors; }
Create errors for a failed validator. @param ValidatorContract $validator @param Closure|null $closure a closure that is bound to the translator. @return ErrorCollection
failedValidator
php
cloudcreativity/laravel-json-api
src/Document/Error/Translator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Translator.php
Apache-2.0
public function failedValidatorException( ValidatorContract $validator, ?Closure $closure = null ): JsonApiException { return new ValidationException( $this->failedValidator($validator, $closure) ); }
Create a JSON API exception for a failed validator. @param ValidatorContract $validator @param Closure|null $closure @return JsonApiException
failedValidatorException
php
cloudcreativity/laravel-json-api
src/Document/Error/Translator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Translator.php
Apache-2.0
public function call(Closure $closure, ...$args): ErrorInterface { return $closure->call($this, ...$args); }
Create an error by calling the closure with it bound to the error translator. @param Closure $closure @param mixed ...$args @return ErrorInterface
call
php
cloudcreativity/laravel-json-api
src/Document/Error/Translator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Translator.php
Apache-2.0
protected function trans(string $key, string $member, array $replace = [], ?string $locale = null) { $value = $this->translator->get( $key = "jsonapi::errors.{$key}.{$member}", $replace, $locale ) ?: null; return ($key !== $value) ? $value : null; }
Translate an error member value. @param string $key the key for the JSON API error object. @param string $member the JSON API error object member name. @param array $replace @param string|null $locale @return string|null
trans
php
cloudcreativity/laravel-json-api
src/Document/Error/Translator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Translator.php
Apache-2.0
protected function pointer(string $path, ?string $member = null): array { /** Member can be '0' which is an empty string. */ $withoutMember = is_null($member) || '' === $member; $pointer = !$withoutMember ? sprintf('%s/%s', rtrim($path, '/'), $member) : $path; return [NeomerxError::SOURCE_POINTER => $pointer]; }
Create a source pointer for the specified path and optional member at that path. @param string $path @param string|null $member @return array
pointer
php
cloudcreativity/laravel-json-api
src/Document/Error/Translator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Translator.php
Apache-2.0
protected function createValidationFailure(string $rule, ?array $options): array { $failure = ['rule' => $this->convertRuleName($rule)]; if (!empty($options) && $this->failedRuleHasOptions($rule)) { $failure['options'] = $options; } return $failure; }
@param string $rule @param array|null $options @return array
createValidationFailure
php
cloudcreativity/laravel-json-api
src/Document/Error/Translator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Translator.php
Apache-2.0
protected function failedRuleHasOptions(string $rule): bool { return !\in_array(strtolower($rule), [ 'exists', 'unique', ], true); }
Should options for the rule be displayed? @param string $rule @return bool
failedRuleHasOptions
php
cloudcreativity/laravel-json-api
src/Document/Error/Translator.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Error/Translator.php
Apache-2.0
public static function cast($value): self { if ($value instanceof self) { return $value; } if (is_array($value)) { return self::fromArray($value); } if (is_string($value)) { return new self($value); } throw new UnexpectedValueException('Expecting a link, string or array.'); }
Cast a value to a link. @param Link|string|array $value @return Link
cast
php
cloudcreativity/laravel-json-api
src/Document/Link/Link.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Link/Link.php
Apache-2.0
public static function fromArray(array $input): self { return new self( $input[self::HREF] ?? '', $input[self::META] ?? null ); }
Create a link from an array. @param array $input @return Link
fromArray
php
cloudcreativity/laravel-json-api
src/Document/Link/Link.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Link/Link.php
Apache-2.0
public function __construct(string $href, array $meta = null) { $this->setHref($href); $this->setMeta($meta); }
Link constructor. @param string $href @param array|null $meta
__construct
php
cloudcreativity/laravel-json-api
src/Document/Link/Link.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Document/Link/Link.php
Apache-2.0
public function __construct(Model $model, ?PagingStrategyInterface $paging = null) { $this->model = $model; $this->paging = $paging; $this->scopes = []; }
AbstractAdapter constructor. @param Model $model @param PagingStrategyInterface|null $paging
__construct
php
cloudcreativity/laravel-json-api
src/Eloquent/AbstractAdapter.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/AbstractAdapter.php
Apache-2.0
public function queryToMany($relation, QueryParametersInterface $parameters) { $this->applyScopes( $query = $this->newRelationQuery($relation) ); return $this->queryAllOrOne( $query, $this->getQueryParameters($parameters) ); }
Query the resource when it appears in a to-many relation of a parent resource. For example, a request to `/posts/1/comments` will invoke this method on the comments adapter. @param Relations\BelongsToMany|Relations\HasMany|Relations\HasManyThrough|Builder $relation @param QueryParametersInterface $parameters @return mixed @todo default pagination causes a problem with polymorphic relations??
queryToMany
php
cloudcreativity/laravel-json-api
src/Eloquent/AbstractAdapter.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/AbstractAdapter.php
Apache-2.0
public function queryToOne($relation, QueryParametersInterface $parameters) { $this->applyScopes( $query = $this->newRelationQuery($relation) ); return $this->queryOne( $query, $this->getQueryParameters($parameters) ); }
Query the resource when it appears in a to-one relation of a parent resource. For example, a request to `/posts/1/author` will invoke this method on the user adapter when the author relation returns a `users` resource. @param Relations\BelongsTo|Relations\HasOne|Builder $relation @param QueryParametersInterface $parameters @return mixed
queryToOne
php
cloudcreativity/laravel-json-api
src/Eloquent/AbstractAdapter.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/AbstractAdapter.php
Apache-2.0
public function addScopes(Scope ...$scopes): self { foreach ($scopes as $scope) { $this->scopes[get_class($scope)] = $scope; } return $this; }
Add scopes. @param Scope ...$scopes @return $this
addScopes
php
cloudcreativity/laravel-json-api
src/Eloquent/AbstractAdapter.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/AbstractAdapter.php
Apache-2.0
public function addClosureScope(Closure $scope, ?string $identifier = null): self { $identifier = $identifier ?: spl_object_hash($scope); $this->scopes[$identifier] = $scope; return $this; }
Add a global scope using a closure. @param Closure $scope @param string|null $identifier @return $this
addClosureScope
php
cloudcreativity/laravel-json-api
src/Eloquent/AbstractAdapter.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/AbstractAdapter.php
Apache-2.0
protected function newQuery() { $this->applyScopes( $builder = $this->model->newQuery() ); return $builder; }
Get a new query builder. Child classes can overload this method if they want to modify the query instance that is used for every query the adapter does. @return Builder
newQuery
php
cloudcreativity/laravel-json-api
src/Eloquent/AbstractAdapter.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/AbstractAdapter.php
Apache-2.0
protected function newRelationQuery($relation) { return $relation->newQuery(); }
@param Relations\BelongsToMany|Relations\HasMany|Relations\HasManyThrough|Builder $relation @return Builder
newRelationQuery
php
cloudcreativity/laravel-json-api
src/Eloquent/AbstractAdapter.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/AbstractAdapter.php
Apache-2.0
protected function readWithFilters($record, QueryParametersInterface $parameters) { $query = $this->newQuery()->whereKey($record->getKey()); $this->applyFilters($query, collect($parameters->getFilteringParameters())); return $query->exists() ? $record : null; }
Does the record match the supplied filters? @param Model $record @param QueryParametersInterface $parameters @return Model|null
readWithFilters
php
cloudcreativity/laravel-json-api
src/Eloquent/AbstractAdapter.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/AbstractAdapter.php
Apache-2.0
protected function applyFilters($query, Collection $filters) { /** * By default we support the `id` filter. If we use the filter, * we remove it so that it is not re-used by the `filter` method. */ if ($this->isFindMany($filters)) { $this->filterByIds($query, $filters); } /** Hook for custom filters. */ $this->filter($query, $filters); }
Apply filters to the provided query parameter. @param Builder $query @param Collection $filters
applyFilters
php
cloudcreativity/laravel-json-api
src/Eloquent/AbstractAdapter.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/AbstractAdapter.php
Apache-2.0
protected function fillRelated( $record, ResourceObject $resource, QueryParametersInterface $parameters ) { $relationships = $resource->getRelationships(); $changed = false; foreach ($relationships as $field => $value) { /** Skip any fields that are not fillable. */ if ($this->isNotFillable($field, $record)) { continue; } /** Skip any fields that are not relations */ if (!$this->isRelation($field)) { continue; } $relation = $this->getRelated($field); if ($this->requiresPrimaryRecordPersistence($relation)) { $relation->update($record, $value, $parameters); $changed = true; } } /** If there are changes, we need to refresh the model in-case the relationship has been cached. */ if ($changed) { $record->refresh(); } }
Hydrate related models after the primary record has been persisted. @param Model $record @param ResourceObject $resource @param QueryParametersInterface $parameters
fillRelated
php
cloudcreativity/laravel-json-api
src/Eloquent/AbstractAdapter.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/AbstractAdapter.php
Apache-2.0
protected function requiresPrimaryRecordPersistence(RelationshipAdapterInterface $relation) { return $relation instanceof HasManyAdapterInterface || $relation instanceof HasOne; }
Does the relationship need to be hydrated after the primary record has been persisted? @param RelationshipAdapterInterface $relation @return bool
requiresPrimaryRecordPersistence
php
cloudcreativity/laravel-json-api
src/Eloquent/AbstractAdapter.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/AbstractAdapter.php
Apache-2.0
protected function filterByIds($query, Collection $filters) { $query->whereIn( $this->getQualifiedKeyName(), $this->extractIds($filters) ); }
@param $query @param Collection $filters @return void
filterByIds
php
cloudcreativity/laravel-json-api
src/Eloquent/AbstractAdapter.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/AbstractAdapter.php
Apache-2.0
protected function searchOne($query) { return $query->first(); }
Return the result for a search one query. @param Builder $query @return Model
searchOne
php
cloudcreativity/laravel-json-api
src/Eloquent/AbstractAdapter.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/AbstractAdapter.php
Apache-2.0
protected function searchAll($query) { return $query->get(); }
Return the result for query that is not paginated. @param Builder $query @return mixed
searchAll
php
cloudcreativity/laravel-json-api
src/Eloquent/AbstractAdapter.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/AbstractAdapter.php
Apache-2.0
protected function isSearchOne(Collection $filters) { return false; }
Is this a search for a singleton resource? @param Collection $filters @return bool
isSearchOne
php
cloudcreativity/laravel-json-api
src/Eloquent/AbstractAdapter.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/AbstractAdapter.php
Apache-2.0
protected function paginate($query, QueryParametersInterface $parameters) { if (!$this->paging) { throw new RuntimeException('Paging is not supported on adapter: ' . get_class($this)); } /** * Set the key name on the strategy, so it knows what column is being used * for the resource's ID. * * @todo 2.0 add `withQualifiedKeyName` to the paging strategy interface. */ if (method_exists($this->paging, 'withQualifiedKeyName')) { $this->paging->withQualifiedKeyName($this->getQualifiedKeyName()); } return $this->paging->paginate($query, $parameters); }
Return the result for a paginated query. @param Builder $query @param QueryParametersInterface $parameters @return PageInterface
paginate
php
cloudcreativity/laravel-json-api
src/Eloquent/AbstractAdapter.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/AbstractAdapter.php
Apache-2.0
protected function getKeyName() { return $this->primaryKey ?: $this->model->getRouteKeyName(); }
Get the key that is used for the resource ID. @return string
getKeyName
php
cloudcreativity/laravel-json-api
src/Eloquent/AbstractAdapter.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/AbstractAdapter.php
Apache-2.0
protected function defaultPagination() { return (array) $this->defaultPagination; }
Get pagination parameters to use when the client has not provided paging parameters. @return array
defaultPagination
php
cloudcreativity/laravel-json-api
src/Eloquent/AbstractAdapter.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/AbstractAdapter.php
Apache-2.0
protected function belongsTo($modelKey = null) { return new BelongsTo($modelKey ?: $this->guessRelation()); }
@param string|null $modelKey @return BelongsTo
belongsTo
php
cloudcreativity/laravel-json-api
src/Eloquent/AbstractAdapter.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/AbstractAdapter.php
Apache-2.0
protected function hasOne($modelKey = null) { return new HasOne($modelKey ?: $this->guessRelation()); }
@param string|null $modelKey @return HasOne
hasOne
php
cloudcreativity/laravel-json-api
src/Eloquent/AbstractAdapter.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/AbstractAdapter.php
Apache-2.0
protected function hasOneThrough($modelKey = null) { return new HasOneThrough($modelKey ?: $this->guessRelation()); }
@param string|null $modelKey @return HasOneThrough
hasOneThrough
php
cloudcreativity/laravel-json-api
src/Eloquent/AbstractAdapter.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/AbstractAdapter.php
Apache-2.0
protected function hasMany($modelKey = null) { return new HasMany($modelKey ?: $this->guessRelation()); }
@param string|null $modelKey @return HasMany
hasMany
php
cloudcreativity/laravel-json-api
src/Eloquent/AbstractAdapter.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/AbstractAdapter.php
Apache-2.0
protected function hasManyThrough($modelKey = null) { return new HasManyThrough($modelKey ?: $this->guessRelation()); }
@param string|null $modelKey @return HasManyThrough
hasManyThrough
php
cloudcreativity/laravel-json-api
src/Eloquent/AbstractAdapter.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/AbstractAdapter.php
Apache-2.0
protected function queriesMany(Closure $factory) { return new QueriesMany($factory); }
@param Closure $factory a factory that creates a new Eloquent query builder. @return QueriesMany
queriesMany
php
cloudcreativity/laravel-json-api
src/Eloquent/AbstractAdapter.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/AbstractAdapter.php
Apache-2.0
protected function queryAllOrOne($query, QueryParametersInterface $parameters) { $filters = collect($parameters->getFilteringParameters()); if ($this->isSearchOne($filters)) { return $this->queryOne($query, $parameters); } return $this->queryAll($query, $parameters); }
Default query execution used when querying records or relations. @param $query @param QueryParametersInterface $parameters @return mixed
queryAllOrOne
php
cloudcreativity/laravel-json-api
src/Eloquent/AbstractAdapter.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/AbstractAdapter.php
Apache-2.0
protected function queryAll($query, QueryParametersInterface $parameters) { /** Apply eager loading */ $this->with($query, $parameters); /** Filter */ $this->applyFilters($query, collect($parameters->getFilteringParameters())); /** Sort */ $this->sort($query, $parameters->getSortParameters()); /** Paginate results if needed. */ $pagination = collect($parameters->getPaginationParameters()); return $pagination->isEmpty() ? $this->searchAll($query) : $this->paginate($query, $parameters); }
@param $query @param QueryParametersInterface $parameters @return PageInterface|mixed
queryAll
php
cloudcreativity/laravel-json-api
src/Eloquent/AbstractAdapter.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/AbstractAdapter.php
Apache-2.0
protected function queryOne($query, QueryParametersInterface $parameters) { $parameters = $this->getQueryParameters($parameters); /** Apply eager loading */ $this->with($query, $parameters); /** Filter */ $this->applyFilters($query, collect($parameters->getFilteringParameters())); /** Sort */ $this->sort($query, $parameters->getSortParameters()); return $this->searchOne($query); }
@param $query @param QueryParametersInterface $parameters @return Model
queryOne
php
cloudcreativity/laravel-json-api
src/Eloquent/AbstractAdapter.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/AbstractAdapter.php
Apache-2.0
protected function getQueryParameters(QueryParametersInterface $parameters) { return new QueryParameters( $parameters->getIncludePaths() ?? $this->getSchema()->getIncludePaths(), $parameters->getFieldSets(), $parameters->getSortParameters() ?: $this->defaultSort(), $parameters->getPaginationParameters() ?: $this->defaultPagination(), $parameters->getFilteringParameters(), $parameters->getUnrecognizedParameters() ); }
Get JSON:API parameters to use when constructing an Eloquent query. This method is used to push in any default parameter values that should be used if the client has not provided any. @param QueryParametersInterface $parameters @return QueryParametersInterface
getQueryParameters
php
cloudcreativity/laravel-json-api
src/Eloquent/AbstractAdapter.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/AbstractAdapter.php
Apache-2.0
public function query($record, QueryParametersInterface $parameters) { $relation = $this->getRelation($record, $this->key); return $this->adapterFor($relation)->queryToMany($relation, $parameters); }
@param Model $record @param QueryParametersInterface $parameters @return mixed
query
php
cloudcreativity/laravel-json-api
src/Eloquent/AbstractManyRelation.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/AbstractManyRelation.php
Apache-2.0
public function query($record, QueryParametersInterface $parameters) { if (!$this->requiresInverseAdapter($record, $parameters)) { return $record->{$this->key}; } $relation = $this->getRelation($record, $this->key); return $this->adapterFor($relation)->queryToOne($relation, $parameters); }
@param Model $record @param QueryParametersInterface $parameters @return mixed
query
php
cloudcreativity/laravel-json-api
src/Eloquent/BelongsTo.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/BelongsTo.php
Apache-2.0
public function relationship($record, QueryParametersInterface $parameters) { return $this->query($record, $parameters); }
@param Model $record @param QueryParametersInterface $parameters @return mixed
relationship
php
cloudcreativity/laravel-json-api
src/Eloquent/BelongsTo.php
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Eloquent/BelongsTo.php
Apache-2.0