|
@@ -316,7 +316,7 @@ discard block |
|
|
block discarded – undo |
|
316
|
316
|
* @param string|array|null $localKey |
|
317
|
317
|
* @return \Staudenmeir\EloquentJsonRelations\Relations\HasOneJson |
|
318
|
318
|
*/ |
|
319
|
|
- public function hasOneJson(string $related, string|array $foreignKey, string|array|null $localKey = null): HasOneJson |
|
|
319
|
+ public function hasOneJson(string $related, string | array $foreignKey, string | array | null $localKey = null): HasOneJson |
|
320
|
320
|
{ |
|
321
|
321
|
/** @var \Illuminate\Database\Eloquent\Model $instance */ |
|
322
|
322
|
$instance = $this->newRelatedInstance($related); |
|
@@ -349,7 +349,7 @@ discard block |
|
|
block discarded – undo |
|
349
|
349
|
* @param string|array $localKey |
|
350
|
350
|
* @return \Staudenmeir\EloquentJsonRelations\Relations\HasOneJson |
|
351
|
351
|
*/ |
|
352
|
|
- protected function newHasOneJson(Builder $query, Model $parent, string|array $foreignKey, string|array $localKey): HasOneJson |
|
|
352
|
+ protected function newHasOneJson(Builder $query, Model $parent, string | array $foreignKey, string | array $localKey): HasOneJson |
|
353
|
353
|
{ |
|
354
|
354
|
return new HasOneJson($query, $parent, $foreignKey, $localKey); |
|
355
|
355
|
} |
|
@@ -368,10 +368,10 @@ discard block |
|
|
block discarded – undo |
|
368
|
368
|
public function hasManyThroughJson( |
|
369
|
369
|
string $related, |
|
370
|
370
|
string $through, |
|
371
|
|
- string|JsonKey $firstKey, |
|
|
371
|
+ string | JsonKey $firstKey, |
|
372
|
372
|
?string $secondKey = null, |
|
373
|
373
|
?string $localKey = null, |
|
374
|
|
- string|JsonKey|null $secondLocalKey = null |
|
|
374
|
+ string | JsonKey | null $secondLocalKey = null |
|
375
|
375
|
) { |
|
376
|
376
|
$relationships = []; |
|
377
|
377
|
|
|
@@ -384,7 +384,7 @@ discard block |
|
|
block discarded – undo |
|
384
|
384
|
} else { |
|
385
|
385
|
if (!method_exists($through, 'belongsToJson')) { |
|
386
|
386
|
//@codeCoverageIgnoreStart |
|
387
|
|
- $message = 'Please add the HasJsonRelationships trait to the ' . $through::class . ' model.'; |
|
|
387
|
+ $message = 'Please add the HasJsonRelationships trait to the '.$through::class.' model.'; |
|
388
|
388
|
|
|
389
|
389
|
throw new RuntimeException($message); |
|
390
|
390
|
// @codeCoverageIgnoreEnd |
|
@@ -423,7 +423,7 @@ discard block |
|
|
block discarded – undo |
|
423
|
423
|
/** @var \Staudenmeir\EloquentJsonRelations\Relations\HasManyJson $hasManyJson */ |
|
424
|
424
|
$hasManyJson = $relationships[0]; |
|
425
|
425
|
|
|
426
|
|
- $postGetCallback = function (Collection $models) use ($hasManyJson, $relationships) { |
|
|
426
|
+ $postGetCallback = function(Collection $models) use ($hasManyJson, $relationships) { |
|
427
|
427
|
if (isset($models[0]->laravel_through_key)) { |
|
428
|
428
|
$hasManyJson->hydratePivotRelation( |
|
429
|
429
|
$models, |
|
@@ -440,7 +440,7 @@ discard block |
|
|
block discarded – undo |
|
440
|
440
|
} |
|
441
|
441
|
|
|
442
|
442
|
$hasManyThroughJson->withCustomEagerMatchingCallback( |
|
443
|
|
- function (array $models, Collection $results, string $relation) use ($hasManyJson, $hasManyThroughJson) { |
|
|
443
|
+ function(array $models, Collection $results, string $relation) use ($hasManyJson, $hasManyThroughJson) { |
|
444
|
444
|
foreach ($models as $model) { |
|
445
|
445
|
$hasManyJson->hydratePivotRelation( |
|
446
|
446
|
$model->$relation, |
|
@@ -458,7 +458,7 @@ discard block |
|
|
block discarded – undo |
|
458
|
458
|
|
|
459
|
459
|
$path = $belongsToJson->getForeignKeyPath(); |
|
460
|
460
|
|
|
461
|
|
- $postProcessor = function (Model $model, array $attributes) use ($belongsToJson, $path) { |
|
|
461
|
+ $postProcessor = function(Model $model, array $attributes) use ($belongsToJson, $path) { |
|
462
|
462
|
$records = json_decode($attributes[$path], true); |
|
463
|
463
|
|
|
464
|
464
|
return $belongsToJson->pivotAttributes($model, $model, $records); |