_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q242600
Encoding.jsonApi
validation
public static function jsonApi(int $options = 0, string $urlPrefix = null, int $depth = 512): self { return self::create( MediaTypeInterface::JSON_API_MEDIA_TYPE, $options, $urlPrefix, $depth ); }
php
{ "resource": "" }
q242601
Encoding.custom
validation
public static function custom($mediaType): self { if (!$mediaType instanceof MediaTypeInterface) { $mediaType = MediaType::parse(0, $mediaType); } return new self($mediaType, null); }
php
{ "resource": "" }
q242602
Encoding.is
validation
public function is(string ...$mediaTypes): bool { $mediaTypes = collect($mediaTypes)->map(function ($mediaType, $index) { return MediaType::parse($index, $mediaType); }); return $this->any(...$mediaTypes); }
php
{ "resource": "" }
q242603
Encoding.accept
validation
public function accept(AcceptMediaTypeInterface $mediaType): bool { // if quality factor 'q' === 0 it means this type is not acceptable (RFC 2616 #3.9) if (0 === $mediaType->getQuality()) { return false; } return $this->matchesTo($mediaType); }
php
{ "resource": "" }
q242604
Cursor.create
validation
public static function create( array $parameters, $beforeKey = 'before', $afterKey = 'after', $limitKey = 'limit' ) { return new self( array_get($parameters, $beforeKey), array_get($parameters, $afterKey), array_get($parameters, $limitKey, 15) ); }
php
{ "resource": "" }
q242605
ServiceProvider.register
validation
public function register() { $this->bindNeomerx(); $this->bindService(); $this->bindInboundRequest(); $this->bindRouteRegistrar(); $this->bindApiRepository(); $this->bindExceptionParser(); $this->bindRenderer(); $this->mergePackageConfig(); }
php
{ "resource": "" }
q242606
ServiceProvider.bootMiddleware
validation
protected function bootMiddleware(Router $router) { $router->aliasMiddleware('json-api', BootJsonApi::class); $router->aliasMiddleware('json-api.content', NegotiateContent::class); $router->aliasMiddleware('json-api.auth', Authorize::class); }
php
{ "resource": "" }
q242607
ServiceProvider.bootResponseMacro
validation
protected function bootResponseMacro() { Response::macro('jsonApi', function ($api = null) { return json_api($api)->getResponses()->withEncodingParameters( app(EncodingParametersInterface::class) ); }); }
php
{ "resource": "" }
q242608
ServiceProvider.bootBladeDirectives
validation
protected function bootBladeDirectives() { /** @var BladeCompiler $compiler */ $compiler = $this->app->make(BladeCompiler::class); $compiler->directive('jsonapi', Renderer::class . '::compileWith'); $compiler->directive('encode', Renderer::class . '::compileEncode'); }
php
{ "resource": "" }
q242609
ServiceProvider.bindService
validation
protected function bindService() { $this->app->singleton(JsonApiService::class); $this->app->alias(JsonApiService::class, 'json-api'); $this->app->alias(JsonApiService::class, 'json-api.service'); }
php
{ "resource": "" }
q242610
ServiceProvider.bindInboundRequest
validation
protected function bindInboundRequest() { $this->app->singleton(JsonApiRequest::class); $this->app->alias(JsonApiRequest::class, 'json-api.request'); $this->app->singleton(Route::class, function (Application $app) { return new Route( $app->make(ResolverInterface::class), $app->make('router')->current() ); }); $this->app->bind(StoreInterface::class, function () { return json_api()->getStore(); }); $this->app->bind(ResolverInterface::class, function () { return json_api()->getResolver(); }); $this->app->bind(ErrorRepositoryInterface::class, function () { return json_api()->getErrors(); }); $this->app->bind(ContainerInterface::class, function () { return json_api()->getContainer(); }); $this->app->singleton(HeaderParametersInterface::class, function (Application $app) { /** @var HeaderParametersParserInterface $parser */ $parser = $app->make(HttpFactoryInterface::class)->createHeaderParametersParser(); /** @var ServerRequestInterface $serverRequest */ $serverRequest = $app->make(ServerRequestInterface::class); return $parser->parse($serverRequest, http_contains_body($serverRequest)); }); $this->app->singleton(EncodingParametersInterface::class, function (Application $app) { /** @var QueryParametersParserInterface $parser */ $parser = $app->make(HttpFactoryInterface::class)->createQueryParametersParser(); return $parser->parseQueryParameters( request()->query() ); }); }
php
{ "resource": "" }
q242611
ServiceProvider.bindExceptionParser
validation
protected function bindExceptionParser() { $this->app->singleton(ExceptionParserInterface::class, ExceptionParser::class); $this->app->alias(ExceptionParserInterface::class, 'json-api.exceptions'); }
php
{ "resource": "" }
q242612
AbstractValidator.make
validation
protected function make(array $data) { $validator = $this->validatorFactory->make( $data, $this->getRules(), $this->getMessages(), $this->getAttributes() ); $this->configureValidator($validator); return $validator; }
php
{ "resource": "" }
q242613
GuardsFields.isFillable
validation
protected function isFillable($field, $record) { /** If the field is listed in the fillable fields, it can be filled. */ if (in_array($field, $fillable = $this->getFillable($record))) { return true; } /** If the field is listed in the guarded fields, it cannot be filled. */ if ($this->isGuarded($field, $record)) { return false; } /** Otherwise we can fill if everything is fillable. */ return empty($fillable); }
php
{ "resource": "" }
q242614
ValidatedRequest.all
validation
public function all() { if (is_array($this->data)) { return $this->data; } return $this->data = $this->route->getCodec()->all($this->request); }
php
{ "resource": "" }
q242615
MakeResource.filterCommands
validation
private function filterCommands(Collection $commands, $type) { $baseCommandName = 'make:json-api:'; $filterValues = explode(',', $this->option($type)); $targetCommands = collect($filterValues) ->map(function ($target) use ($baseCommandName) { return $baseCommandName . strtolower(trim($target)); }); return $commands->{$type}($targetCommands->toArray()); }
php
{ "resource": "" }
q242616
MakeResource.runCommandsWithParameters
validation
private function runCommandsWithParameters(Collection $commands, array $parameters) { foreach ($commands->keys() as $command) { if (0 !== $this->call($command, $parameters)) { return false; } } return true; }
php
{ "resource": "" }
q242617
AbstractValidator.validateTypeMember
validation
protected function validateTypeMember($value, string $path): bool { if (!is_string($value)) { $this->memberNotString($path, 'type'); return false; } if (empty($value)) { $this->memberEmpty($path, 'type'); return false; } if (!$this->store->isType($value)) { $this->resourceTypeNotRecognised($value, $path); return false; } return true; }
php
{ "resource": "" }
q242618
AbstractValidator.validateIdMember
validation
protected function validateIdMember($value, string $path): bool { if (!is_string($value)) { $this->memberNotString($path, 'id'); return false; } if (empty($value)) { $this->memberEmpty($path, 'id'); return false; } return true; }
php
{ "resource": "" }
q242619
AbstractValidator.validateIdentifier
validation
protected function validateIdentifier($value, string $path, ?int $index = null): bool { $member = is_int($index) ? (string) $index : 'data'; if (!is_object($value)) { $this->memberNotObject($path, $member); return false; } $dataPath = sprintf('%s/%s', rtrim($path, '/'), $member); $valid = true; if (!property_exists($value, 'type')) { $this->memberRequired($dataPath, 'type'); $valid = false; } else if (!$this->validateTypeMember($value->type, $dataPath)) { $valid = false; } if (!property_exists($value, 'id')) { $this->memberRequired($dataPath, 'id'); $valid = false; } else if (!$this->validateIdMember($value->id, $dataPath)) { $valid = false; } /** If it has attributes or relationships, it is a resource object not a resource identifier */ if (property_exists($value, 'attributes') || property_exists($value, 'relationships')) { $this->memberNotIdentifier($path, $member); $valid = false; } return $valid; }
php
{ "resource": "" }
q242620
AbstractValidator.validateRelationship
validation
protected function validateRelationship($relation, ?string $field = null): bool { $path = $field ? '/data/relationships' : '/'; $member = $field ?: 'data'; if (!is_object($relation)) { $this->memberNotObject($path, $member); return false; } $path = $field ? "{$path}/{$field}" : $path; if (!property_exists($relation, 'data')) { $this->memberRequired($path, 'data'); return false; } $data = $relation->data; if (is_array($data)) { return $this->validateToMany($data, $field); } return $this->validateToOne($data, $field); }
php
{ "resource": "" }
q242621
AbstractValidator.validateToOne
validation
protected function validateToOne($value, ?string $field = null): bool { if (is_null($value)) { return true; } $dataPath = $field ? "/data/relationships/{$field}" : "/"; $identifierPath = $field ? "/data/relationships/{$field}" : "/data"; if (!$this->validateIdentifier($value, $dataPath)) { return false; } if (!$this->store->exists(new ResourceIdentifier($value))) { $this->resourceDoesNotExist($identifierPath); return false; } return true; }
php
{ "resource": "" }
q242622
AbstractValidator.validateToMany
validation
protected function validateToMany(array $value, ?string $field = null): bool { $path = $field ? "/data/relationships/{$field}/data" : "/data"; $valid = true; foreach ($value as $index => $item) { if (!$this->validateIdentifier($item, $path, $index)) { $valid = false; continue; } if ($this->isNotFound($item->type, $item->id)) { $this->resourceDoesNotExist("{$path}/{$index}"); $valid = false; } } return $valid; }
php
{ "resource": "" }
q242623
AbstractValidator.dataHas
validation
protected function dataHas($key): bool { if (!isset($this->document->data)) { return false; } return property_exists($this->document->data, $key); }
php
{ "resource": "" }
q242624
AbstractValidator.dataGet
validation
protected function dataGet($key, $default = null) { if (!isset($this->document->data)) { return $default; } return data_get($this->document->data, $key, $default); }
php
{ "resource": "" }
q242625
AbstractValidator.isNotFound
validation
protected function isNotFound(string $type, string $id): bool { return !$this->store->exists(ResourceIdentifier::create($type, $id)); }
php
{ "resource": "" }
q242626
AbstractValidator.memberRequired
validation
protected function memberRequired(string $path, string $member): void { $this->errors->add($this->translator->memberRequired($path, $member)); }
php
{ "resource": "" }
q242627
AbstractValidator.memberFieldsNotAllowed
validation
protected function memberFieldsNotAllowed(string $path, string $member, iterable $fields): void { foreach ($fields as $field) { $this->errors->add($this->translator->memberFieldNotAllowed($path, $member, $field)); } }
php
{ "resource": "" }
q242628
AbstractValidator.resourceTypeNotSupported
validation
protected function resourceTypeNotSupported(string $actual, string $path = '/data'): void { $this->errors->add($this->translator->resourceTypeNotSupported($actual, $path)); }
php
{ "resource": "" }
q242629
AbstractValidator.resourceDoesNotSupportClientIds
validation
protected function resourceDoesNotSupportClientIds(string $type, string $path = '/data'): void { $this->errors->add($this->translator->resourceDoesNotSupportClientIds($type, $path)); }
php
{ "resource": "" }
q242630
AbstractValidator.resourceExists
validation
protected function resourceExists(string $type, string $id, string $path = '/data'): void { $this->errors->add($this->translator->resourceExists($type, $id, $path)); }
php
{ "resource": "" }
q242631
AbstractValidator.resourceDoesNotExist
validation
protected function resourceDoesNotExist(string $path): void { $this->errors->add($this->translator->resourceDoesNotExist($path)); }
php
{ "resource": "" }
q242632
AbstractValidator.resourceFieldsExistInAttributesAndRelationships
validation
protected function resourceFieldsExistInAttributesAndRelationships(iterable $fields): void { foreach ($fields as $field) { $this->errors->add( $this->translator->resourceFieldExistsInAttributesAndRelationships($field) ); } }
php
{ "resource": "" }
q242633
HandlesErrors.isJsonApi
validation
public function isJsonApi($request, Exception $e) { if (Helpers::wantsJsonApi($request)) { return true; } /** @var Route $route */ $route = app(JsonApiService::class)->currentRoute(); return $route->hasCodec() && $route->getCodec()->willEncode(); }
php
{ "resource": "" }
q242634
HandlesErrors.prepareJsonApiException
validation
protected function prepareJsonApiException(JsonApiException $ex) { $error = collect($ex->getErrors())->map(function (ErrorInterface $err) { return $err->getDetail() ?: $err->getTitle(); })->filter()->first(); return new HttpException($ex->getHttpCode(), $error, $ex); }
php
{ "resource": "" }
q242635
Responses.withMediaType
validation
public function withMediaType(string $mediaType): self { if (!$encoding = $this->api->getEncodings()->find($mediaType)) { throw new \InvalidArgumentException( "Media type {$mediaType} is not valid for API {$this->api->getName()}." ); } $codec = $this->factory->createCodec( $this->api->getContainer(), $encoding, null ); return $this->withCodec($codec); }
php
{ "resource": "" }
q242636
Responses.withEncoding
validation
public function withEncoding( int $options = 0, int $depth = 512, string $mediaType = MediaTypeInterface::JSON_API_MEDIA_TYPE ) { $encoding = Encoding::create( $mediaType, $options, $this->api->getUrl()->toString(), $depth ); $codec = $this->factory->createCodec( $this->api->getContainer(), $encoding, null ); return $this->withCodec($codec); }
php
{ "resource": "" }
q242637
Responses.updated
validation
public function updated( $resource = null, array $links = [], $meta = null, array $headers = [] ) { return $this->getResourceResponse($resource, $links, $meta, $headers); }
php
{ "resource": "" }
q242638
Responses.deleted
validation
public function deleted( $resource = null, array $links = [], $meta = null, array $headers = [] ) { return $this->getResourceResponse($resource, $links, $meta, $headers); }
php
{ "resource": "" }
q242639
Responses.error
validation
public function error($error, $defaultStatusCode = null, array $headers = []) { if (is_string($error)) { $error = $this->api->getErrors()->error($error); } else if (is_array($error)) { $error = Error::create($error); } if (!$error instanceof ErrorInterface) { throw new \InvalidArgumentException('Expecting a string, array or error object.'); } return $this->errors($error, $defaultStatusCode, $headers); }
php
{ "resource": "" }
q242640
Responses.errors
validation
public function errors($errors, $defaultStatusCode = null, array $headers = []) { if ($errors instanceof ErrorResponseInterface) { return $this->getErrorResponse($errors); } if (is_array($errors)) { $errors = $this->api->getErrors()->errors(...$errors); } return $this->errors( $this->factory->createErrorResponse($errors, $defaultStatusCode, $headers) ); }
php
{ "resource": "" }
q242641
Responses.exception
validation
public function exception(\Exception $ex) { /** If the current codec cannot encode JSON API, we need to reset it. */ if ($this->getCodec()->willNotEncode()) { $this->codec = $this->api->getDefaultCodec(); } return $this->getErrorResponse( $this->exceptions->parse($ex) ); }
php
{ "resource": "" }
q242642
Responses.isNoContent
validation
protected function isNoContent($resource, $links, $meta) { return is_null($resource) && empty($links) && empty($meta); }
php
{ "resource": "" }
q242643
ClientException.getErrors
validation
public function getErrors() { if (!is_null($this->errors)) { return collect($this->errors); } try { $this->errors = $this->parse(); } catch (\Exception $ex) { $this->errors = []; } return collect($this->errors); }
php
{ "resource": "" }
q242644
ClientException.parse
validation
private function parse() { if (!$this->response) { return []; } $body = json_decode((string) $this->response->getBody(), true); return isset($body['errors']) ? $body['errors'] : []; }
php
{ "resource": "" }
q242645
HasMany.add
validation
public function add($record, array $relationship, EncodingParametersInterface $parameters) { $related = $this->findRelated($record, $relationship); $relation = $this->getRelation($record, $this->key); $existing = $relation ->getQuery() ->whereKey($related->modelKeys()) ->get(); $relation->saveMany($related->diff($existing)); $record->refresh(); // in case the relationship has been cached. return $record; }
php
{ "resource": "" }
q242646
HasMany.findRelated
validation
protected function findRelated($record, array $relationship) { $inverse = $this->getRelation($record, $this->key)->getRelated(); $related = $this->findToMany($relationship); $related = collect($related)->filter(function ($model) use ($inverse) { return $model instanceof $inverse; }); return new Collection($related); }
php
{ "resource": "" }
q242647
SerializesModels.getDefaultAttributes
validation
protected function getDefaultAttributes(Model $model) { $defaults = []; if ($this->hasCreatedAtAttribute($model)) { $createdAt = $model->getCreatedAtColumn(); $field = $this->fieldForAttribute($createdAt); $defaults[$field] = $this->extractAttribute($model, $createdAt, $field); } if ($this->hasUpdatedAtAttribute($model)) { $updatedAt = $model->getUpdatedAtColumn(); $field = $this->fieldForAttribute($updatedAt); $defaults[$field] = $this->extractAttribute($model, $updatedAt, $field); } if ($this->hasDeletedAtAttribute($model)) { $deletedAt = $model->getDeletedAtColumn(); $field = $this->fieldForAttribute($deletedAt); $defaults[$field] = $this->extractAttribute($model, $deletedAt, $field); } return $defaults; }
php
{ "resource": "" }
q242648
SerializesModels.getModelAttributes
validation
protected function getModelAttributes(Model $model) { $attributes = []; foreach ($this->attributeKeys($model) as $modelKey => $field) { if (is_numeric($modelKey)) { $modelKey = $field; $field = $this->fieldForAttribute($field); } $attributes[$field] = $this->extractAttribute($model, $modelKey, $field); } return $attributes; }
php
{ "resource": "" }
q242649
SerializesModels.attributeKeys
validation
protected function attributeKeys(Model $model) { if (is_array($this->attributes)) { return $this->attributes; } return $model->getVisible(); }
php
{ "resource": "" }
q242650
ErrorTranslator.memberRequired
validation
public function memberRequired(string $path, string $member): ErrorInterface { return new Error( 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) ); }
php
{ "resource": "" }
q242651
ErrorTranslator.resourceTypeNotRecognised
validation
public function resourceTypeNotRecognised(string $type, string $path = '/data'): ErrorInterface { return new Error( 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') ); }
php
{ "resource": "" }
q242652
ErrorTranslator.resourceIdNotSupported
validation
public function resourceIdNotSupported(string $id, string $path = '/data'): ErrorInterface { return new Error( 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') ); }
php
{ "resource": "" }
q242653
ErrorTranslator.resourceDoesNotSupportClientIds
validation
public function resourceDoesNotSupportClientIds(string $type, string $path = '/data'): ErrorInterface { return new Error( 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') ); }
php
{ "resource": "" }
q242654
ErrorTranslator.resourceDoesNotExist
validation
public function resourceDoesNotExist(string $path): ErrorInterface { return new Error( 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) ); }
php
{ "resource": "" }
q242655
ErrorTranslator.resourceCannotBeDeleted
validation
public function resourceCannotBeDeleted(string $detail = null): ErrorInterface { return new Error( 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') ); }
php
{ "resource": "" }
q242656
ErrorTranslator.invalidResource
validation
public function invalidResource( string $path, ?string $detail = null, array $failed = [] ): ErrorInterface { return new Error( 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), $failed ? compact('failed') : null ); }
php
{ "resource": "" }
q242657
ErrorTranslator.invalidQueryParameter
validation
public function invalidQueryParameter(string $param, ?string $detail = null, array $failed = []): ErrorInterface { return new Error( null, null, Response::HTTP_BAD_REQUEST, $this->trans('query_invalid', 'code'), $this->trans('query_invalid', 'title'), $detail ?: $this->trans('query_invalid', 'detail'), [Error::SOURCE_PARAMETER => $param], $failed ? compact('failed') : null ); }
php
{ "resource": "" }
q242658
ErrorTranslator.failedValidator
validation
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) { $failed = $failures->shift() ?: []; if ($closure) { $errors->add($this->call($closure, $key, $detail, $failed)); continue; } $errors->add(new Error( null, null, Response::HTTP_UNPROCESSABLE_ENTITY, $this->trans('failed_validator', 'code'), $this->trans('failed_validator', 'title'), $detail ?: $this->trans('failed_validator', 'detail') )); } } return $errors; }
php
{ "resource": "" }
q242659
ErrorTranslator.failedValidatorException
validation
public function failedValidatorException( ValidatorContract $validator, \Closure $closure = null ): JsonApiException { return new ValidationException( $this->failedValidator($validator, $closure) ); }
php
{ "resource": "" }
q242660
ErrorTranslator.trans
validation
protected function trans(string $key, string $member, array $replace = [], ?string $locale = null) { return $this->translator->trans( "jsonapi::errors.{$key}.{$member}", $replace, $locale ) ?: null; }
php
{ "resource": "" }
q242661
ErrorTranslator.pointer
validation
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 [Error::SOURCE_POINTER => $pointer]; }
php
{ "resource": "" }
q242662
CreatesEloquentIdentities.createBelongsToIdentity
validation
protected function createBelongsToIdentity(Model $model, $relationshipKey) { $relation = $model->{$relationshipKey}(); if (!$relation instanceof BelongsTo) { throw new RuntimeException(sprintf( 'Expecting %s on %s to be a belongs-to relationship.', $relationshipKey, get_class($model) )); } // support Laravel 5.8 $foreignKey = method_exists($relation, 'getForeignKeyName') ? $relation->getForeignKeyName() : $relation->getForeignKey(); $id = $model->{$foreignKey}; if (is_null($id)) { return null; } // support Laravel 5.8 $ownerKey = method_exists($relation, 'getOwnerKeyName') ? $relation->getOwnerKeyName() : $relation->getOwnerKey(); $related = $relation->getRelated()->replicate(); $related->{$ownerKey} = $id; return $related; }
php
{ "resource": "" }
q242663
CreatesEloquentIdentities.createModelIdentity
validation
protected function createModelIdentity( $modelClass, $id, $keyName = null ) { if (is_null($id)) { return null; } $model = new $modelClass(); if (!$model instanceof Model) { throw new RuntimeException(sprintf('Expecting a model class, got %s.', $modelClass)); } $model->setAttribute($keyName ?: $model->getRouteKeyName(), $id); return $model; }
php
{ "resource": "" }
q242664
IncludesModels.with
validation
protected function with($query, EncodingParametersInterface $parameters) { $query->with($this->getRelationshipPaths( (array) $parameters->getIncludePaths() )); }
php
{ "resource": "" }
q242665
IncludesModels.load
validation
protected function load($record, EncodingParametersInterface $parameters) { $relationshipPaths = $this->getRelationshipPaths($parameters->getIncludePaths()); $record->loadMissing($relationshipPaths); }
php
{ "resource": "" }
q242666
IncludesModels.getRelationshipPaths
validation
protected function getRelationshipPaths($includePaths) { return $this ->convertIncludePaths($includePaths) ->merge($this->defaultWith) ->unique() ->all(); }
php
{ "resource": "" }
q242667
IncludesModels.convertIncludePath
validation
protected function convertIncludePath($path) { if (array_key_exists($path, $this->includePaths)) { return $this->includePaths[$path] ?: null; } return collect(explode('.', $path))->map(function ($segment) { return $this->modelRelationForField($segment); })->implode('.'); }
php
{ "resource": "" }
q242668
IncludesModels.modelRelationForField
validation
protected function modelRelationForField($field) { return $this->camelCaseRelations ? Str::camelize($field) : Str::underscore($field); }
php
{ "resource": "" }
q242669
Error.createMany
validation
public static function createMany(array $input) { $errors = new ErrorCollection(); foreach ($input as $item) { $errors->add(self::create($item)); } return $errors; }
php
{ "resource": "" }
q242670
SoftDeletesModels.fillSoftDelete
validation
protected function fillSoftDelete(Model $record, $field, $value) { $value = $this->deserializeSoftDelete( $value, $field, $record ); $record->forceFill([ $this->getSoftDeleteKey($record) => $value, ]); }
php
{ "resource": "" }
q242671
SoftDeletesModels.deserializeSoftDelete
validation
protected function deserializeSoftDelete($value, $field, $record) { if (collect([true, false, 1, 0, '1', '0'])->containsStrict($value)) { return $value ? Carbon::now() : null; } return $this->deserializeAttribute($value, $field, $record); }
php
{ "resource": "" }
q242672
SoftDeletesModels.getSoftDeleteField
validation
protected function getSoftDeleteField(Model $record) { if ($field = $this->softDeleteField()) { return $field; } $key = $this->getSoftDeleteKey($record); return Str::dasherize($key); }
php
{ "resource": "" }
q242673
AbstractAllowedRule.allow
validation
public function allow(string ...$params): self { $this->all = false; foreach ($params as $param) { $this->allowed->put($param, $param); } return $this; }
php
{ "resource": "" }
q242674
Str.dasherize
validation
public static function dasherize($value) { if (isset(self::$dasherized[$value])) { return self::$dasherized[$value]; } return self::$dasherized[$value] = str_replace('_', '-', self::decamelize($value)); }
php
{ "resource": "" }
q242675
Str.decamelize
validation
public static function decamelize($value) { if (isset(self::$decamelized[$value])) { return self::$decamelized[$value]; } return self::$decamelized[$value] = strtolower(preg_replace('/(.)(?=[A-Z])/u', '$1_', $value)); }
php
{ "resource": "" }
q242676
Str.underscore
validation
public static function underscore($value) { if (isset(self::$underscored[$value])) { return self::$underscored[$value]; } return self::$underscored[$value] = str_replace('-', '_', self::decamelize($value)); }
php
{ "resource": "" }
q242677
Str.camelize
validation
public static function camelize($value) { if (isset(self::$camelized[$value])) { return self::$camelized[$value]; } return self::$camelized[$value] = lcfirst(self::classify($value)); }
php
{ "resource": "" }
q242678
Str.classify
validation
public static function classify($value) { if (isset(self::$classified[$value])) { return self::$classified[$value]; } $converted = ucwords(str_replace(['-', '_'], ' ', $value)); return self::$classified[$value] = str_replace(' ', '', $converted); }
php
{ "resource": "" }
q242679
AbstractGeneratorCommand.buildClass
validation
protected function buildClass($name) { $stub = $this->files->get($this->getStub()); $this->replaceNamespace($stub, $name) ->replaceClassName($stub, $name) ->replaceResourceType($stub) ->replaceApplicationNamespace($stub) ->replaceRecord($stub); return $stub; }
php
{ "resource": "" }
q242680
AbstractGeneratorCommand.getStub
validation
protected function getStub() { if ($this->isIndependent) { return $this->getStubFor('independent'); } if ($this->isEloquent()) { return $this->getStubFor('eloquent'); } return $this->getStubFor('abstract'); }
php
{ "resource": "" }
q242681
AbstractGeneratorCommand.getResourceName
validation
protected function getResourceName() { $name = ucwords($this->getResourceInput()); if ($this->isByResource()) { return str_plural($name); } return $name; }
php
{ "resource": "" }
q242682
AbstractGeneratorCommand.replaceResourceType
validation
protected function replaceResourceType(&$stub) { $resource = $this->getResourceName(); $stub = str_replace('dummyResourceType', Str::dasherize($resource), $stub); return $this; }
php
{ "resource": "" }
q242683
AbstractGeneratorCommand.replaceRecord
validation
protected function replaceRecord(&$stub) { $resource = $this->getResourceName(); $stub = str_replace('DummyRecord', Str::classify(str_singular($resource)), $stub); return $this; }
php
{ "resource": "" }
q242684
AbstractGeneratorCommand.replaceApplicationNamespace
validation
protected function replaceApplicationNamespace(&$stub) { $namespace = rtrim($this->laravel->getNamespace(), '\\'); $stub = str_replace('DummyApplicationNamespace', $namespace, $stub); return $this; }
php
{ "resource": "" }
q242685
AbstractGeneratorCommand.getStubFor
validation
protected function getStubFor($implementationType) { return sprintf( '%s/%s/%s.stub', $this->stubsDirectory, $implementationType, Str::dasherize($this->type) ); }
php
{ "resource": "" }
q242686
AbstractGeneratorCommand.isEloquent
validation
protected function isEloquent() { if ($this->isIndependent) { return false; } if ($this->option('no-eloquent')) { return false; } return $this->option('eloquent') ?: $this->getApi()->isEloquent(); }
php
{ "resource": "" }
q242687
AbstractValidators.dataForUpdate
validation
protected function dataForUpdate($record, array $document): array { $resource = $document['data'] ?? []; if ($this->mustValidateExisting($record, $document)) { $resource['attributes'] = $this->extractAttributes( $record, $resource['attributes'] ?? [] ); $resource['relationships'] = $this->extractRelationships( $record, $resource['relationships'] ?? [] ); } return $resource; }
php
{ "resource": "" }
q242688
AbstractValidators.dataForDelete
validation
protected function dataForDelete($record): array { $schema = $this->container->getSchema($record); return ResourceObject::create([ 'type' => $schema->getResourceType(), 'id' => $schema->getId($record), 'attributes' => $schema->getAttributes($record), 'relationships' => collect($this->existingRelationships($record))->all(), ])->all(); }
php
{ "resource": "" }
q242689
AbstractValidators.dataForRelationship
validation
protected function dataForRelationship($record, string $field, array $document): array { $schema = $this->container->getSchema($record); return [ 'type' => $schema->getResourceType(), 'id' => $schema->getId($record), 'relationships' => [ $field => [ 'data' => $document['data'], ], ], ]; }
php
{ "resource": "" }
q242690
AbstractValidators.relationshipRules
validation
protected function relationshipRules($record, string $field): array { return collect($this->rules($record))->filter(function ($v, $key) use ($field) { return Str::startsWith($key, $field); })->all(); }
php
{ "resource": "" }
q242691
AbstractValidators.validatorForResource
validation
protected function validatorForResource( array $data, array $rules, array $messages = [], array $customAttributes = [] ): ValidatorInterface { return $this->factory->createResourceValidator( ResourceObject::create($data), $rules, $messages, $customAttributes ); }
php
{ "resource": "" }
q242692
AbstractValidators.validatorForDelete
validation
protected function validatorForDelete( array $data, array $rules, array $messages = [], array $customAttributes = [] ): ValidatorInterface { return $this->createValidator( $data, $rules, $messages, $customAttributes ); }
php
{ "resource": "" }
q242693
AbstractValidators.createValidator
validation
protected function createValidator( array $data, array $rules, array $messages = [], array $customAttributes = [] ): ValidatorInterface { return $this->factory->createDeleteValidator($data, $rules, $messages, $customAttributes); }
php
{ "resource": "" }
q242694
AbstractValidators.excluded
validation
protected function excluded(string ...$keys): Collection { return collect($keys)->mapWithKeys(function ($key) { return [$key => new DisallowedParameter($key)]; }); }
php
{ "resource": "" }
q242695
AbstractRelationshipValidator.validateRelationship
validation
protected function validateRelationship(RelationshipInterface $relationship, $key = null) { if (!$relationship->has(RelationshipInterface::DATA)) { $this->addError($this->errorFactory->memberRequired( RelationshipInterface::DATA, $key ? P::relationship($key) : P::data() )); return false; } if (!$relationship->isHasOne() && !$relationship->isHasMany()) { $this->addError($this->errorFactory->memberRelationshipExpected( RelationshipInterface::DATA, $key ? P::relationship($key) : P::data() )); return false; } if (!$this->validateEmpty($relationship, $key)) { return false; } return true; }
php
{ "resource": "" }
q242696
AbstractRelationshipValidator.validateHasOne
validation
protected function validateHasOne( RelationshipInterface $relationship, $record = null, $key = null, ResourceObjectInterface $resource = null ) { if (!$relationship->isHasOne()) { $this->addError($this->errorFactory->relationshipHasOneExpected($key)); return false; } $identifier = $relationship->getData(); if (!$identifier) { return true; } /** Validate the identifier */ if (!$this->validateIdentifier($identifier, $key)) { return false; } /** If an identifier has been provided, the resource it references must exist. */ if (!$this->validateExists($identifier, $key)) { return false; } /** If an identifier has been provided, is it acceptable for the relationship? */ if (!$this->validateAcceptable($identifier, $record, $key, $resource)) { return false; } return true; }
php
{ "resource": "" }
q242697
AbstractRelationshipValidator.validateHasMany
validation
protected function validateHasMany( RelationshipInterface $relationship, $record = null, $key = null, ResourceObjectInterface $resource = null ) { if (!$relationship->isHasMany()) { $this->addError($this->errorFactory->relationshipHasManyExpected($key)); return false; } $identifiers = $relationship->getIdentifiers(); if (!$this->validateIdentifiers($identifiers, $record, $key, $resource)) { return false; } return true; }
php
{ "resource": "" }
q242698
CursorBuilder.next
validation
protected function next(Cursor $cursor, $columns) { if ($cursor->isAfter()) { $this->whereId($cursor->getAfter(), $this->descending ? '<' : '>'); } $items = $this ->orderForNext() ->get($cursor->getLimit() + 1, $columns); $more = $items->count() > $cursor->getLimit(); return new CursorPaginator( $items->slice(0, $cursor->getLimit()), $more, $cursor, $this->key ); }
php
{ "resource": "" }
q242699
CursorBuilder.previous
validation
protected function previous(Cursor $cursor, $columns) { $items = $this ->whereId($cursor->getBefore(), $this->descending ? '>' : '<') ->orderForPrevious() ->get($cursor->getLimit(), $columns) ->reverse() ->values(); return new CursorPaginator($items, true, $cursor, $this->key); }
php
{ "resource": "" }