103 lines
3.2 KiB
PHP
103 lines
3.2 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Created by Reliese Model.
|
|
*/
|
|
|
|
namespace App\Models;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* Class BookingFile
|
|
*
|
|
* @property int $id
|
|
* @property int $booking_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 Booking $booking
|
|
* @package App\Models
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingFile newModelQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingFile newQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingFile query()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingFile whereBookingId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingFile whereCreatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingFile whereDir($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingFile whereExt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingFile whereFilename($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingFile whereId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingFile whereIdentifier($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingFile whereMine($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingFile whereOriginalName($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingFile whereSize($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BookingFile whereUpdatedAt($value)
|
|
* @mixin \Eloquent
|
|
*/
|
|
class BookingFile extends Model
|
|
{
|
|
protected $table = 'booking_files';
|
|
|
|
protected $casts = [
|
|
'booking_id' => 'int',
|
|
'size' => 'int'
|
|
];
|
|
|
|
protected $fillable = [
|
|
'booking_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 booking()
|
|
{
|
|
return $this->belongsTo(Booking::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, 'booking', $do]);
|
|
}
|
|
|
|
public function getPath(){
|
|
return \Storage::disk('booking')->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;
|
|
}
|
|
}
|
|
}
|