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

Commit 9ec153c

Browse files
fix: laravel 7 compatibility
1 parent e431a49 commit 9ec153c

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
],
1111
"minimum-stability": "stable",
1212
"require": {
13-
"php": ">=7.2",
14-
"laravel/framework": "^6.0|^7.0"
13+
"php": ">=7.2.5",
14+
"laravel/framework": "^7.4"
1515
},
1616
"require-dev": {
17-
"phpunit/phpunit": "^8.0",
18-
"orchestra/testbench": "^3.9",
19-
"mockery/mockery": "^1.2"
17+
"phpunit/phpunit": "^8.5",
18+
"orchestra/testbench": "^5.0",
19+
"mockery/mockery": "^1.3.1"
2020
},
2121
"autoload": {
2222
"psr-4": {

src/HasTranslations.php

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function translations(): HasMany
6060
/**
6161
* Check if the translation by the given locale exists.
6262
*
63-
* @param string $locale
63+
* @param string $locale
6464
* @return bool
6565
*/
6666
public function translationExists(string $locale): bool
@@ -148,8 +148,8 @@ public function getTranslatableAttributes(): array
148148
}
149149

150150
/**
151-
* @param string $locale
152-
* @param array<string, mixed> $attributes
151+
* @param string $locale
152+
* @param array<string, mixed> $attributes
153153
* @return \Illuminate\Database\Eloquent\Model
154154
*/
155155
public function storeTranslation(string $locale, array $attributes = [])
@@ -170,7 +170,7 @@ public function storeTranslation(string $locale, array $attributes = [])
170170
/**
171171
* Store many translations at once.
172172
*
173-
* @param array<string, array> $translations
173+
* @param array<string, array> $translations
174174
* @return $this
175175
*/
176176
public function storeTranslations(array $translations)
@@ -183,7 +183,7 @@ public function storeTranslations(array $translations)
183183
}
184184

185185
/**
186-
* @param string $locale
186+
* @param string $locale
187187
* @return \Illuminate\Database\Eloquent\Model|self
188188
*/
189189
public function getTranslation(string $locale)
@@ -192,8 +192,8 @@ public function getTranslation(string $locale)
192192
}
193193

194194
/**
195-
* @param string $locale
196-
* @param string $name
195+
* @param string $locale
196+
* @param string $name
197197
* @return mixed
198198
*/
199199
public function getTranslationValue(string $locale, string $name)
@@ -208,7 +208,7 @@ public function getTranslationValue(string $locale, string $name)
208208
*/
209209
public function getLocaleKeyName(): string
210210
{
211-
return property_exists($this, 'localeKeyName')
211+
return property_exists($this, 'localeKeyName')
212212
? $this->localeKeyName
213213
: config()->get('translatable.locale_key_name', 'locale');
214214
}
@@ -221,14 +221,15 @@ public function getLocaleKeyName(): string
221221
public function getLocale(): string
222222
{
223223
return null !== $this->currentLocale
224-
? $this->currentLocale
224+
? $this->currentLocale
225225
: app()->getLocale();
226226
}
227227

228228
/**
229229
* Refresh the translation (in the current locale).
230230
*
231231
* @return \Illuminate\Database\Eloquent\Model|null|HasTranslations
232+
* @throws \KoenHoeijmakers\LaravelTranslatable\Exceptions\MissingTranslationsException
232233
*/
233234
public function refreshTranslation()
234235
{
@@ -252,7 +253,7 @@ public function refreshTranslation()
252253
/**
253254
* Translate the model to the given locale.
254255
*
255-
* @param string $locale
256+
* @param string $locale
256257
* @return \Illuminate\Database\Eloquent\Model|null
257258
*/
258259
public function translate(string $locale)
@@ -270,6 +271,7 @@ public function translate(string $locale)
270271
* Format the translated columns.
271272
*
272273
* @return array
274+
* @throws \KoenHoeijmakers\LaravelTranslatable\Exceptions\MissingTranslationsException
273275
*/
274276
public function formatTranslatableColumnsForSelect(): array
275277
{
@@ -295,10 +297,13 @@ public function newQueryWithoutScopes(): Builder
295297
* Retrieve the model for a bound value.
296298
*
297299
* @param mixed $value
300+
* @param null $field
298301
* @return \Illuminate\Database\Eloquent\Model|null
299302
*/
300-
public function resolveRouteBinding($value)
303+
public function resolveRouteBinding($value, $field = null)
301304
{
302-
return $this->newQuery()->where($this->getTable() . '.' . $this->getRouteKeyName(), $value)->first();
305+
$field = $field ?? $this->getRouteKeyName();
306+
307+
return $this->newQuery()->where($this->getTable() . '.' . $field, $value)->first();
303308
}
304309
}

0 commit comments

Comments
 (0)