mein-sterntours/app/Models/LeadFile.php
2021-11-09 18:38:44 +01:00

114 lines
3.2 KiB
PHP

<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
/**
* Class LeadFile
*
* @property int $id
* @property int $lead_id
* @property int $lead_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 Lead $lead
* @property LeadMail $lead_mail
* @package App\Models
* @method static \Illuminate\Database\Eloquent\Builder|LeadFile newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|LeadFile newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|LeadFile query()
* @method static \Illuminate\Database\Eloquent\Builder|LeadFile whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|LeadFile whereDir($value)
* @method static \Illuminate\Database\Eloquent\Builder|LeadFile whereExt($value)
* @method static \Illuminate\Database\Eloquent\Builder|LeadFile whereFilename($value)
* @method static \Illuminate\Database\Eloquent\Builder|LeadFile whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|LeadFile whereIdentifier($value)
* @method static \Illuminate\Database\Eloquent\Builder|LeadFile whereLeadId($value)
* @method static \Illuminate\Database\Eloquent\Builder|LeadFile whereLeadMailId($value)
* @method static \Illuminate\Database\Eloquent\Builder|LeadFile whereMine($value)
* @method static \Illuminate\Database\Eloquent\Builder|LeadFile whereOriginalName($value)
* @method static \Illuminate\Database\Eloquent\Builder|LeadFile whereSize($value)
* @method static \Illuminate\Database\Eloquent\Builder|LeadFile whereUpdatedAt($value)
* @mixin \Eloquent
*/
class LeadFile extends Model
{
protected $table = 'lead_files';
protected $casts = [
'lead_id' => 'int',
'lead_mail_id' => 'int',
'size' => 'int'
];
protected $fillable = [
'lead_id',
'lead_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 lead()
{
return $this->belongsTo(Lead::class);
}
public function lead_mail()
{
return $this->belongsTo(LeadMail::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, 'lead', $do]);
}
public function getPath(){
return \Storage::disk('lead')->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;
}
}
}