✏️ Edit: Product.php
Path:
/home/thiqat5/tmphone.thiqatech.com/tm/app/Model/Product.php
Size: 1.38 KB · Modified: 2021-11-17 23:00:14 · Perm: 0644 · Writable
← Back to directory
👁 View
⬇ Download
<?php namespace App\Model; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\DB; use Illuminate\Database\Eloquent\Builder; class Product extends Model { protected $casts = [ 'tax' => 'float', 'price' => 'float', 'status' => 'integer', 'discount' => 'float', 'set_menu' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime', 'wishlist_count' => 'integer', 'total_stock' => 'integer', ]; public function translations() { return $this->morphMany('App\Model\Translation', 'translationable'); } public function scopeActive($query) { return $query->where('status', '=', 1); } public function reviews() { return $this->hasMany(Review::class)->latest(); } public function wishlist() { return $this->hasMany(Wishlist::class)->latest(); } public function rating() { return $this->hasMany(Review::class) ->select(DB::raw('avg(rating) average, product_id')) ->groupBy('product_id'); } protected static function booted() { static::addGlobalScope('translate', function (Builder $builder) { $builder->with(['translations' => function($query){ return $query->where('locale', app()->getLocale()); }]); }); } }
💾 Save
Cancel
Save as UTF-8, newlines normalized to LF