Skip to content

Commit

Permalink
fix: adjust function to internal changes
Browse files Browse the repository at this point in the history
  • Loading branch information
taka-oyama committed Feb 14, 2022
1 parent db075c5 commit 44a594a
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/Colopl/Spanner/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

use Colopl\Spanner\Query\Builder as QueryBuilder;
use Illuminate\Database\Eloquent\Model as BaseModel;
use Illuminate\Support\Collection;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Str;

/**
Expand All @@ -43,7 +44,7 @@ class Model extends BaseModel
/**
* Method overridden so that the class returns the query builder for Spanner
*
* @return \Illuminate\Database\Query\Builder
* @return Builder
*/
protected function newBaseQueryBuilder()
{
Expand All @@ -55,35 +56,36 @@ protected function newBaseQueryBuilder()
}

/**
* @param BaseModel|Relation $query
* @param mixed $value
* @param string|null $field
* @return BaseModel|null
* @param string|null $field
* @return Relation
*/
public function resolveRouteBinding($value, $field = null)
public function resolveRouteBindingQuery($query, $value, $field = null)
{
// value needs to be casted to prevent "No matching signature" error.
// Ex: if table is INT64 and value is string it would throw this error.
$key = $field ?? $this->getRouteKeyName();
return parent::resolveRouteBinding($this->tryCastAttribute($key, $value), $field);
return parent::resolveRouteBindingQuery($query, $this->tryCastAttribute($key, $value), $field);
}

/**
* @param string $childType
* @param mixed $value
* @param string|null $field
* @return BaseModel|null
* @return Relation
*/
public function resolveChildRouteBinding($childType, $value, $field)
protected function resolveChildRouteBindingQuery($childType, $value, $field)
{
$relationship = $this->{Str::plural(Str::camel($childType))}();
$key = $field ?: $relationship->getRelated()->getRouteKeyName();
return parent::resolveChildRouteBinding($childType, $this->tryCastAttribute($key, $value), $field);
return parent::resolveChildRouteBindingQuery($childType, $this->tryCastAttribute($key, $value), $field);
}

/**
* @param string $key
* @param mixed $value
* @return bool|Collection|int|mixed|string|null
* @return mixed
*/
protected function tryCastAttribute(string $key, $value)
{
Expand Down

0 comments on commit 44a594a

Please sign in to comment.