'object', ]; protected $fillable = [ 'product_id', 'user_wl_product_id', 'type', 'filename', 'original_name', 'ext', 'mine', 'size', 'pos', 'active', 'attributes', ]; public function sluggable(): array { return [ 'slug' => [ 'source' => 'original_name', ], ]; } public function product() { return $this->belongsTo('App\Models\Product', 'product_id'); } public function user_wl_product() { return $this->belongsTo('App\Models\UserWhitelabelProduct', 'user_wl_product_id'); } public function formatBytes($precision = 2) { $size = $this->size; if ($size > 0) { $size = (int) $size; $base = log($size) / log(1024); $suffixes = [' bytes', ' KB', ' MB', ' GB', ' TB']; return round(pow(1024, $base - floor($base)), $precision).$suffixes[floor($base)]; } else { return $size; } } public function getImagePath() { if ($this->type === 'uwllogo') { return '/images/user_product/'.$this->user_wl_product_id.'/'.$this->filename; } if ($this->type === 'product') { return '/images/product/'.$this->product_id.'/'.$this->filename; } if ($this->type === 'wllogo') { return '/images/product/'.$this->product_id.'/'.$this->filename; } return '/images/product/'.$this->product_id.'/'.$this->filename; } public function getBaseImagePath() { return base_path().'/storage/app/public'.$this->getImagePath(); } }