feat: finalize i18n everywhere (monicahq/chandler#479)
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
@@ -71,6 +72,7 @@ class Module extends Model
|
||||
protected $fillable = [
|
||||
'account_id',
|
||||
'name',
|
||||
'name_translation_key',
|
||||
'type',
|
||||
'can_be_deleted',
|
||||
'reserved_to_contact_information',
|
||||
@@ -111,4 +113,24 @@ class Module extends Model
|
||||
return $this->belongsToMany(TemplatePage::class, 'module_template_page')
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name attribute.
|
||||
* Modules have a default name that can be translated.
|
||||
* Howerer, if a name is set, it will be used instead of the default.
|
||||
*
|
||||
* @return Attribute<string,never>
|
||||
*/
|
||||
protected function name(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: function ($value, $attributes) {
|
||||
if (! $value) {
|
||||
return __($attributes['name_translation_key']);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user