65 lines
1.6 KiB
PHP
65 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Cviebrock\EloquentSluggable\Sluggable;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class UserShopOnSite extends Model
|
|
{
|
|
use Sluggable;
|
|
|
|
protected $table = 'user_shop_on_sites';
|
|
|
|
protected $fillable = [
|
|
'user_shop_id', 'filename', 'original_name', 'ext', 'mine', 'size'
|
|
];
|
|
|
|
public function sluggable()
|
|
{
|
|
return [
|
|
'slug' => [
|
|
'source' => 'original_name'
|
|
]
|
|
];
|
|
}
|
|
|
|
public function product()
|
|
{
|
|
return $this->belongsTo('App\Models\UserShop', 'user_shop_id');
|
|
}
|
|
|
|
public function formatBytes($precision = 2)
|
|
{
|
|
$size = $this->size;
|
|
|
|
if ($size > 0) {
|
|
$size = (int) $size;
|
|
$base = log($size) / log(1024);
|
|
$suffixes = array(' bytes', ' KB', ' MB', ' GB', ' TB');
|
|
|
|
return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)];
|
|
} else {
|
|
return $size;
|
|
}
|
|
}
|
|
|
|
|
|
public function isImage(){
|
|
if(empty($this->attributes['filename']) || @$this->attributes['filename'] == null || @$this->attributes['filename'] == ""){
|
|
return false;
|
|
}
|
|
if(!\Storage::disk('public')->has('images/shop/'.$this->filename)){
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public function getImage(){
|
|
if($this->isImage()){
|
|
$link = 'images/shop/'.$this->filename;
|
|
return '/storage/'.$link.'?=lm='.\Storage::disk('public')->lastModified($link);
|
|
}
|
|
return false;
|
|
}
|
|
}
|