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

106 lines
3.3 KiB
PHP

<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
/**
* Class GeneralFile
*
* @property int $id
* @property int $travel_country_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 TravelCountry $travel_country
* @package App\Models
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\GeneralFile newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\GeneralFile newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\GeneralFile query()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\GeneralFile whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\GeneralFile whereDir($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\GeneralFile whereExt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\GeneralFile whereFilename($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\GeneralFile whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\GeneralFile whereIdentifier($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\GeneralFile whereMine($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\GeneralFile whereOriginalName($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\GeneralFile whereSize($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\GeneralFile whereTravelCountryId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\GeneralFile whereUpdatedAt($value)
* @mixin \Eloquent
*/
class GeneralFile extends Model
{
protected $connection = 'mysql';
protected $table = 'general_files';
protected $casts = [
'travel_country_id' => 'int',
'size' => 'int'
];
protected $fillable = [
'travel_country_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_country()
{
return $this->belongsTo(TravelCountry::class, 'travel_country_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, 'general', $do]);
}
public function getPath(){
return \Storage::disk('general')->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;
}
}
}