You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

67 lines
1.5 KiB

<?php
namespace App\Models;
use App\Models\Traits\Validatable;
use App\Models\Traits\ValidationMaker;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
class File extends Model
{
use HasFactory, SoftDeletes;
protected $primaryKey = 'uuid';
public $incrementing = false;
protected $fillable = [
"uuid",
"original_name",
"ext",
"mimetype",
"width",
"server_path",
"height",
"file_size",
"sort",
"alts",
"description",
"user_id",
"ip",
"model_id",
"collection_id",
"published_at",
];
protected $casts = [
'alts' => 'array',
];
protected function alts(): Attribute
{
return Attribute::make(
set: fn ($value) => json_encode($value),
);
}
public function collection()
{
return $this->belongsTo(Collection::class);
}
public function getPath()
{
return Storage::disk($this->collection->disk)->path($this->server_path . $this->uuid . '.' . $this->collection->ext);
}
public function getModifiedPath()
{
return Storage::disk(app()->collection->disk)->path(app()->file->server_path . app()->file->uuid . '-modified.' . app()->collection->ext);
}
}