Skip to content
This repository has been archived by the owner on Jun 18, 2019. It is now read-only.

normalize foreign key #575

Merged
merged 3 commits into from
Jun 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions src/Translatable/Translatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,10 @@ public function getTranslationModelNamespace()
public function getRelationKey()
{
if ($this->translationForeignKey) {
$key = $this->translationForeignKey;
} elseif ($this->primaryKey !== 'id') {
$key = $this->primaryKey;
} else {
$key = $this->getForeignKey();
return $this->translationForeignKey;
}

return $key;
return $this->getForeignKey();
}

/**
Expand Down Expand Up @@ -204,7 +200,7 @@ private function getAttributeOrFallback($locale, $attribute)
*/
public function getAttribute($key)
{
list($attribute, $locale) = $this->getAttributeAndLocale($key);
[$attribute, $locale] = $this->getAttributeAndLocale($key);

if ($this->isTranslationAttribute($attribute)) {
if ($this->getTranslation($locale) === null) {
Expand Down Expand Up @@ -234,7 +230,7 @@ public function getAttribute($key)
*/
public function setAttribute($key, $value)
{
list($attribute, $locale) = $this->getAttributeAndLocale($key);
[$attribute, $locale] = $this->getAttributeAndLocale($key);

if ($this->isTranslationAttribute($attribute)) {
$this->getTranslationOrNew($locale)->$attribute = $value;
Expand Down Expand Up @@ -304,7 +300,7 @@ public function fill(array $attributes)
$this->getTranslationOrNew($key)->fill($values);
unset($attributes[$key]);
} else {
list($attribute, $locale) = $this->getAttributeAndLocale($key);
[$attribute, $locale] = $this->getAttributeAndLocale($key);
if ($this->isTranslationAttribute($attribute) and $this->isKeyALocale($locale)) {
$this->getTranslationOrNew($locale)->fill([$attribute => $values]);
unset($attributes[$key]);
Expand Down