FlashDeal.php 713 B

1234567891011121314151617181920212223242526
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use App;
  5. class FlashDeal extends Model
  6. {
  7. protected $with = ['flash_deal_translations'];
  8. public function getTranslation($field = '', $lang = false){
  9. $lang = $lang == false ? App::getLocale() : $lang;
  10. $flash_deal_translation = $this->flash_deal_translations->where('lang', $lang)->first();
  11. return $flash_deal_translation != null ? $flash_deal_translation->$field : $this->$field;
  12. }
  13. public function flash_deal_translations(){
  14. return $this->hasMany(FlashDealTranslation::class);
  15. }
  16. public function flash_deal_products()
  17. {
  18. return $this->hasMany(FlashDealProduct::class);
  19. }
  20. }