File: D:/HostingSpaces/fire-tech/fire-tech.nl/app/KommaApp/Kms/Core/AbstractTranslatableModel.php
<?php
namespace App\KommaApp\Kms\Core;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Support\Facades\App;
/**
* Represents a eloquent model that has a translation method to retrieve translations
*
* Interface TranslatableModelInterface
* @package App\KommaApp\Kms\Core
*/
abstract class AbstractTranslatableModel extends Model
{
//Make also sure that your model has a title attribute! Used in section header
/**
* Gets the translation models for this model
*
* @return HasMany that resolves to AbstractTranslationModel instances
*/
abstract public function translations(): HasMany;
/**
* Looks at the app language and searches the matching translation model for it.
*
* @throws \RuntimeException
*/
public function translation(): HasOne
{
$languageId = App::getLanguage()->id;
$translationsModel = get_class($this->translations()->getRelated());
return $this->hasOne($translationsModel)->where('language_id', '=', $languageId);
}
}