Page.php 508 B

12345678910111213141516171819
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use App;
  5. class Page extends Model
  6. {
  7. public function getTranslation($field = '', $lang = false){
  8. $lang = $lang == false ? App::getLocale() : $lang;
  9. $page_translation = $this->hasMany(PageTranslation::class)->where('lang', $lang)->first();
  10. return $page_translation != null ? $page_translation->$field : $this->$field;
  11. }
  12. public function page_translations(){
  13. return $this->hasMany(PageTranslation::class);
  14. }
  15. }