mein-sterntours/app/Models/TravelUserBookingFile.php
2020-05-28 19:03:42 +02:00

106 lines
3.6 KiB
PHP

<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
/**
* Class TravelUserBookingFile
*
* @property int $id
* @property int $travel_user_booking_fewos
* @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 TravelUserBookingFewo $travel_user_booking_fewo
* @package App\Models
* @property int|null $travel_user_booking_fewo_id
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFile newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFile newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFile query()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFile whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFile whereDir($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFile whereExt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFile whereFilename($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFile whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFile whereIdentifier($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFile whereMine($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFile whereOriginalName($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFile whereSize($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFile whereTravelUserBookingFewoId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelUserBookingFile whereUpdatedAt($value)
* @mixin \Eloquent
*/
class TravelUserBookingFile extends Model
{
protected $connection = 'mysql_stern';
protected $table = 'travel_user_booking_files';
protected $casts = [
'travel_user_booking_fewo_id' => 'int',
'size' => 'int'
];
protected $fillable = [
'travel_user_booking_fewo_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 travel_user_booking_fewo()
{
return $this->belongsTo(TravelUserBookingFewo::class, 'travel_user_booking_fewo_id');
}
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_fewo', $do]);
}
public function getPath(){
return \Storage::disk('booking_fewo')->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;
}
}
}