Skip to content
This repository has been archived by the owner on Aug 17, 2021. It is now read-only.

Commit

Permalink
fix: laravel 7 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
koenhoeijmakers committed Apr 4, 2020
1 parent e431a49 commit 9ec153c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
],
"minimum-stability": "stable",
"require": {
"php": ">=7.2",
"laravel/framework": "^6.0|^7.0"
"php": ">=7.2.5",
"laravel/framework": "^7.4"
},
"require-dev": {
"phpunit/phpunit": "^8.0",
"orchestra/testbench": "^3.9",
"mockery/mockery": "^1.2"
"phpunit/phpunit": "^8.5",
"orchestra/testbench": "^5.0",
"mockery/mockery": "^1.3.1"
},
"autoload": {
"psr-4": {
Expand Down
29 changes: 17 additions & 12 deletions src/HasTranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function translations(): HasMany
/**
* Check if the translation by the given locale exists.
*
* @param string $locale
* @param string $locale
* @return bool
*/
public function translationExists(string $locale): bool
Expand Down Expand Up @@ -148,8 +148,8 @@ public function getTranslatableAttributes(): array
}

/**
* @param string $locale
* @param array<string, mixed> $attributes
* @param string $locale
* @param array<string, mixed> $attributes
* @return \Illuminate\Database\Eloquent\Model
*/
public function storeTranslation(string $locale, array $attributes = [])
Expand All @@ -170,7 +170,7 @@ public function storeTranslation(string $locale, array $attributes = [])
/**
* Store many translations at once.
*
* @param array<string, array> $translations
* @param array<string, array> $translations
* @return $this
*/
public function storeTranslations(array $translations)
Expand All @@ -183,7 +183,7 @@ public function storeTranslations(array $translations)
}

/**
* @param string $locale
* @param string $locale
* @return \Illuminate\Database\Eloquent\Model|self
*/
public function getTranslation(string $locale)
Expand All @@ -192,8 +192,8 @@ public function getTranslation(string $locale)
}

/**
* @param string $locale
* @param string $name
* @param string $locale
* @param string $name
* @return mixed
*/
public function getTranslationValue(string $locale, string $name)
Expand All @@ -208,7 +208,7 @@ public function getTranslationValue(string $locale, string $name)
*/
public function getLocaleKeyName(): string
{
return property_exists($this, 'localeKeyName')
return property_exists($this, 'localeKeyName')
? $this->localeKeyName
: config()->get('translatable.locale_key_name', 'locale');
}
Expand All @@ -221,14 +221,15 @@ public function getLocaleKeyName(): string
public function getLocale(): string
{
return null !== $this->currentLocale
? $this->currentLocale
? $this->currentLocale
: app()->getLocale();
}

/**
* Refresh the translation (in the current locale).
*
* @return \Illuminate\Database\Eloquent\Model|null|HasTranslations
* @throws \KoenHoeijmakers\LaravelTranslatable\Exceptions\MissingTranslationsException
*/
public function refreshTranslation()
{
Expand All @@ -252,7 +253,7 @@ public function refreshTranslation()
/**
* Translate the model to the given locale.
*
* @param string $locale
* @param string $locale
* @return \Illuminate\Database\Eloquent\Model|null
*/
public function translate(string $locale)
Expand All @@ -270,6 +271,7 @@ public function translate(string $locale)
* Format the translated columns.
*
* @return array
* @throws \KoenHoeijmakers\LaravelTranslatable\Exceptions\MissingTranslationsException
*/
public function formatTranslatableColumnsForSelect(): array
{
Expand All @@ -295,10 +297,13 @@ public function newQueryWithoutScopes(): Builder
* Retrieve the model for a bound value.
*
* @param mixed $value
* @param null $field
* @return \Illuminate\Database\Eloquent\Model|null
*/
public function resolveRouteBinding($value)
public function resolveRouteBinding($value, $field = null)
{
return $this->newQuery()->where($this->getTable() . '.' . $this->getRouteKeyName(), $value)->first();
$field = $field ?? $this->getRouteKeyName();

return $this->newQuery()->where($this->getTable() . '.' . $field, $value)->first();
}
}

0 comments on commit 9ec153c

Please sign in to comment.