Role.php 556 B

123456789101112131415161718192021
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use App;
  5. class Role extends Model
  6. {
  7. protected $with = ['role_translations'];
  8. public function getTranslation($field = '', $lang = false){
  9. $lang = $lang == false ? App::getLocale() : $lang;
  10. $role_translation = $this->role_translations->where('lang', $lang)->first();
  11. return $role_translation != null ? $role_translation->$field : $this->$field;
  12. }
  13. public function role_translations(){
  14. return $this->hasMany(RoleTranslation::class);
  15. }
  16. }