/
home
/
henzagold
/
server
/
app
/
Models
/
File Upload :
llllll
Current File: /home/henzagold/server/app/Models/Product.php
<?php namespace App\Models; use App\DB\Selector; use App\Models\Major\Promotion; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Facades\Auth; use phpDocumentor\Reflection\Types\Boolean; class Product extends Model { use HasFactory; use SoftDeletes,Selector; //protected $connection = 'pgsql'; protected $table = 'product'; protected $fillable = [ 'title', 'body_html', 'desk_note', 'product_code', 'indicator_id_id', 'mobile_pic_id', 'number_of_purchase', 'is_active', 'brand_id', 'disabled', 'file_id', 'show_type', 'delivery_type', 'message_long_delivery', 'count_fav', 'count_order', 'count_view', 'min_gram', 'max_gram', 'offer_day',//پیشنهاد روز 'branch_id', 'inventory_id', 'is_exist', 'has_warranty' ]; public static $SHOWType = [ 1 => 'سایت', 2 => 'گوشی', 3 => 'سایت و گوشی', ]; public static $DELIVERYType = [ 1 => 'کوتاه مدت', 2 => 'بلند مدت', ]; protected $casts = [ 'is_active' => 'boolean', 'disabled' => 'boolean', 'offer_day' => 'boolean', 'is_exist' => 'boolean', 'has_warranty' => 'boolean', ]; public function scopeCool($query) { return $query->select(['']); } public function images() { return $this->hasMany('App\Models\ProductImage', 'product_id')->mobile()->with('image'); } public function ciny() { return $this->hasMany(CinyProduct::class, 'product_id'); } // public function gallery() // { // return $this->hasMany('App\Models\ProductImage', 'product_id')->desktop()->with('image'); // } public function thumb() { return $this->belongsTo('App\Models\Image', 'indicator_id_id')->select(['id', 'image', Image::$SELECT_FULL]); } public function tmobile() { return $this->belongsTo('App\Models\Image', 'mobile_pic_id')->select(['id', 'image', Image::$SELECT_FULL]); } public function variants() { return $this->hasMany('App\Models\ProductVariant', 'product_id_id')->where('is_active',true); } public function variantsAll() { return $this->hasMany('App\Models\ProductVariant', 'product_id_id'); } public function variantOne() { return $this->hasOne('App\Models\ProductVariant', 'product_id_id')->where('is_active',true); } public function variantsPromotion() { return $this->hasMany('App\Models\ProductVariant', 'product_id_id'); } public function collect() { return $this->hasMany('App\Models\Collect', 'product_id_id'); } public function category() { return $this->hasOne('App\Models\Collect', 'product_id_id'); /*return $this->hasOneThrough( Category::class, Collect::class, 'product_id_id', 'id', 'id', 'collection_id_id');*/ } public function image() { return $this->belongsTo('App\Models\Image', 'indicator_id_id');//->select(['id' , 'image' , Image::$SELECT_FULL]); } public function brand() { //return $this->belongsTo('App\Models\ConfigStatic', 'brand_id'); return $this->belongsTo('App\Models\ProductBrand', 'brand_id'); } public function gallery() { return $this->hasManyThrough( Image::class, ProductImage::class, 'product_id', 'id', 'id', 'image_id', )->whereNull('w'); } public static function safeDelete($productId) { Product::findOrFail($productId)->delete(); ProductVariant::where('product_id_id', $productId)->delete(); Collect::where('product_id_id', $productId)->delete(); return true; } public function scopeMobile($query) { return $query->where('show_type', 2)->orWhere('show_type', 3)->where('is_active',true); } public function scopeSite($query) { return $query->whereIn('show_type', [1,3])->where('is_active',true); } public function scopeActive($query) { return $query->where('is_active',true); } public function file() { return $this->belongsTo('App\Models\Image', 'file_id'); } public function tags() { return $this->hasMany('App\Models\ProductTags', 'product_id')->with(['cnt'=>function($q){return $q->select(['id' , 'val' , 'key']);}]); } public function promotion() { return $this->hasOne('App\Models\PromotionProduct', 'product_id') ->where('active',true) ->where('start_at','<=',now()) ->where('end_at','>=',now()) ->orderBy('discount','desc'); } public function inventory() { return $this->hasMany(InventoryBranch::class, 'product_id'); } public function branch() { return $this->belongsTo(Branch::class); } }
Copyright ©2k19 -
Hexid
|
Tex7ure