Skip to content

Commit b0f99e8

Browse files
committed
autofix
1 parent d978fbc commit b0f99e8

File tree

2 files changed

+45
-34
lines changed

2 files changed

+45
-34
lines changed

src/Database/Eloquent/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ public function newModelInstance($attributes = [])
652652
->setConnection($this->query->getConnection()->getName());
653653
}
654654

655-
public function create ($attributes = [])
655+
public function create($attributes = [])
656656
{
657657
return tap($this->newModelInstance($attributes), static function ($instance) {
658658
$instance->save();

src/Database/Eloquent/Model.php

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ abstract class Model implements ArrayAccess, UrlRoutable, Arrayable, Jsonable, J
3838

3939
/**
4040
* Indicates if the model exists.
41-
*
42-
* @var bool
4341
*/
4442
public bool $exists = false;
4543

44+
public bool $wasRecentlyCreated = false;
45+
4646
/**
4747
* Indicates if an exception should be thrown when trying to access a missing attribute on a retrieved model.
4848
*
@@ -110,8 +110,6 @@ abstract class Model implements ArrayAccess, UrlRoutable, Arrayable, Jsonable, J
110110
*/
111111
protected static $booted = [];
112112

113-
public bool $wasRecentlyCreated = false;
114-
115113
/**
116114
* Create a new Eloquent model instance.
117115
*/
@@ -454,43 +452,31 @@ public function setTable(string $table): self
454452

455453
public function resolveRouteBinding($value, $field = null): ?Model
456454
{
457-
return $this->resolveRouteBindingQuery($this, $value, $field)->first();
455+
return $this->resolveRouteBindingQuery($this, $value, $field)
456+
->first();
458457
}
459458

460459
public function resolveSoftDeletableRouteBinding(mixed $value, ?string $field = null): ?Model
461460
{
462-
return $this->resolveRouteBindingQuery($this, $value, $field)->withTrashed()->first();
461+
return $this->resolveRouteBindingQuery($this, $value, $field)
462+
->withTrashed()
463+
->first();
463464
}
464465

465466
public function resolveChildRouteBinding($childType, $value, $field): ?Model
466467
{
467-
return $this->resolveChildRouteBindingQuery($childType, $value, $field)->first();
468-
}
469-
470-
public function resolveSoftDeletableChildRouteBinding(string $childType, mixed $value, ?string $field = null): ?Model
471-
{
472-
return $this->resolveChildRouteBindingQuery($childType, $value, $field)->withTrashed()->first();
473-
}
474-
475-
protected function resolveChildRouteBindingQuery(string $childType, mixed $value, ?string $field = null): Relation|Model
476-
{
477-
$relationship = $this->{$this->childRouteBindingRelationshipName($childType)}();
478-
479-
$field = $field ?: $relationship->getRelated()->getRouteKeyName();
480-
481-
if ($relationship instanceof HasManyThrough ||
482-
$relationship instanceof BelongsToMany) {
483-
$field = $relationship->getRelated()->getTable().'.'.$field;
484-
}
485-
486-
return $relationship instanceof Model
487-
? $relationship->resolveRouteBindingQuery($relationship, $value, $field)
488-
: $relationship->getRelated()->resolveRouteBindingQuery($relationship, $value, $field);
468+
return $this->resolveChildRouteBindingQuery($childType, $value, $field)
469+
->first();
489470
}
490471

491-
protected function childRouteBindingRelationshipName(string $childType): string
492-
{
493-
return Str::plural(Str::camel($childType));
472+
public function resolveSoftDeletableChildRouteBinding(
473+
string $childType,
474+
mixed $value,
475+
?string $field = null
476+
): ?Model {
477+
return $this->resolveChildRouteBindingQuery($childType, $value, $field)
478+
->withTrashed()
479+
->first();
494480
}
495481

496482
public function resolveRouteBindingQuery(Relation|Model $query, mixed $value, ?string $field = null): Builder
@@ -584,8 +570,6 @@ public function getPerPage(): int
584570

585571
/**
586572
* Set the number of models to return per page.
587-
*
588-
* @return static
589573
*/
590574
public function setPerPage(int $perPage): static
591575
{
@@ -642,6 +626,33 @@ public static function preventsAccessingMissingAttributes(): bool
642626
return static::$modelsShouldPreventAccessingMissingAttributes;
643627
}
644628

629+
protected function resolveChildRouteBindingQuery(
630+
string $childType,
631+
mixed $value,
632+
?string $field = null
633+
): Relation|Model {
634+
$relationship = $this->{$this->childRouteBindingRelationshipName($childType)}();
635+
636+
$field = $field !== null && $field !== '' && $field !== '0' ? $field : $relationship->getRelated()
637+
->getRouteKeyName();
638+
639+
if ($relationship instanceof HasManyThrough ||
640+
$relationship instanceof BelongsToMany) {
641+
$field = $relationship->getRelated()
642+
->getTable().'.'.$field;
643+
}
644+
645+
return $relationship instanceof Model
646+
? $relationship->resolveRouteBindingQuery($relationship, $value, $field)
647+
: $relationship->getRelated()
648+
->resolveRouteBindingQuery($relationship, $value, $field);
649+
}
650+
651+
protected function childRouteBindingRelationshipName(string $childType): string
652+
{
653+
return Str::plural(Str::camel($childType));
654+
}
655+
645656
/**
646657
* Check if the model needs to be booted and if so, do it.
647658
*/

0 commit comments

Comments
 (0)