122 lines
3.7 KiB
PHP
122 lines
3.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Created by Reliese Model.
|
|
*/
|
|
|
|
namespace App\Models;
|
|
|
|
use App\User;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* Class CustomerFile
|
|
*
|
|
* @property int $id
|
|
* @property int $customer_id
|
|
* @property int $customer_mail_id
|
|
* @property string $identifier
|
|
* @property string $filename
|
|
* @property string $dir
|
|
* @property string $original_name
|
|
* @property string $ext
|
|
* @property string $mine
|
|
* @property int $size
|
|
* @property Carbon $created_at
|
|
* @property Carbon $updated_at
|
|
* @property Customer $customer
|
|
* @property CustomerMail $customer_mail
|
|
* @package App\Models
|
|
* @property-read \App\User $user
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerFile newModelQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerFile newQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerFile query()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerFile whereCreatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerFile whereCustomerId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerFile whereCustomerMailId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerFile whereDir($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerFile whereExt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerFile whereFilename($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerFile whereId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerFile whereIdentifier($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerFile whereMine($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerFile whereOriginalName($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerFile whereSize($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CustomerFile whereUpdatedAt($value)
|
|
* @mixin \Eloquent
|
|
*/
|
|
class CustomerFile extends Model
|
|
{
|
|
protected $connection = 'mysql';
|
|
|
|
protected $table = 'customer_files';
|
|
|
|
protected $casts = [
|
|
'customer_id' => 'int',
|
|
'customer_mail_id' => 'int',
|
|
'size' => 'int'
|
|
];
|
|
|
|
protected $fillable = [
|
|
'customer_id',
|
|
'customer_mail_id',
|
|
'identifier',
|
|
'filename',
|
|
'dir',
|
|
'original_name',
|
|
'ext',
|
|
'mine',
|
|
'size'
|
|
];
|
|
|
|
public static $icon_ext = [
|
|
'default' => 'fa fa-file',
|
|
'pdf'=> 'fa fa-file-pdf',
|
|
'jpg'=> 'fa fa-file-image',
|
|
'png'=> 'fa fa-file-image',
|
|
];
|
|
|
|
public function customer()
|
|
{
|
|
return $this->belongsTo(Customer::class);
|
|
}
|
|
|
|
public function customer_mail()
|
|
{
|
|
return $this->belongsTo(CustomerMail::class);
|
|
}
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function getIconExt(){
|
|
return isset(self::$icon_ext[$this->ext]) ? self::$icon_ext[$this->ext] : self::$icon_ext['default'];
|
|
}
|
|
|
|
public function getURL($do=false){
|
|
return route('storage_file', [$this->id, 'customer', $do]);
|
|
}
|
|
|
|
public function getPath(){
|
|
return \Storage::disk('customer')->path($this->dir.$this->filename);
|
|
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|