D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
forge
/
developers.ghanempharmacy.com
/
app
/
Models
/
Filename :
Attribute.php
back
Copy
<?php namespace App\Models; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Support\Facades\App; /** * @property int $id * @property string $name */ class Attribute extends Model { protected $fillable = [ 'name', ]; protected $casts = [ 'id' => 'integer', 'name' => 'string' ]; public function translations(): MorphMany { return $this->morphMany('App\Models\Translation', 'translationable'); } protected static function boot(): void { parent::boot(); static::addGlobalScope('translate', function (Builder $builder) { $builder->with(['translations' => function ($query) { if (strpos(url()->current(), '/api')) { return $query->where('locale', App::getLocale()); } else { return $query->where('locale', getDefaultLanguage()); } }]); }); } }