Skip to content

Commit

Permalink
Fix resolveRouteBindingQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
leMaur committed Oct 18, 2023
1 parent 2858cf6 commit 1dd528a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Concerns/HasHuids.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Lemaur\HumanId\Concerns;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Database\Eloquent\Relations\Relation;
Expand Down Expand Up @@ -67,11 +68,11 @@ public function newUniqueId(): string
* @param Model|Relation $query
* @param mixed $value
* @param string|null $field
* @return Relation
* @return Relation|Builder
*
* @throws ModelNotFoundException
*/
public function resolveRouteBindingQuery($query, $value, $field = null): Relation
public function resolveRouteBindingQuery($query, $value, $field = null): Relation|Builder
{
if ($field && ! Str::isHuid($value) && in_array($field, $this->uniqueIds(), true)) {
throw (new ModelNotFoundException)->setModel(get_class($this), $value);
Expand All @@ -81,6 +82,10 @@ public function resolveRouteBindingQuery($query, $value, $field = null): Relatio
throw (new ModelNotFoundException)->setModel(get_class($this), $value);
}

if ($field === null && Str::isHuid($value)) {
$field = (string) config('human-id.field', 'huid');
}

return parent::resolveRouteBindingQuery($query, $value, $field);
}

Expand Down

0 comments on commit 1dd528a

Please sign in to comment.