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

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <?php
  2. namespace App\Models;
  3. use App\Models\Traits\Validatable;
  4. use App\Models\Traits\ValidationMaker;
  5. use Illuminate\Database\Eloquent\Casts\Attribute;
  6. use Illuminate\Database\Eloquent\Factories\HasFactory;
  7. use Illuminate\Database\Eloquent\Model;
  8. use Illuminate\Database\Eloquent\SoftDeletes;
  9. use Illuminate\Support\Facades\Storage;
  10. use Illuminate\Support\Str;
  11. class File extends Model
  12. {
  13. use HasFactory, SoftDeletes;
  14. protected $primaryKey = 'uuid';
  15. public $incrementing = false;
  16. protected $fillable = [
  17. "uuid",
  18. "original_name",
  19. "ext",
  20. "mimetype",
  21. "width",
  22. "server_path",
  23. "height",
  24. "file_size",
  25. "sort",
  26. "alts",
  27. "description",
  28. "user_id",
  29. "ip",
  30. "model_id",
  31. "collection_id",
  32. "published_at",
  33. ];
  34. protected $casts = [
  35. 'alts' => 'array',
  36. ];
  37. protected function alts(): Attribute
  38. {
  39. return Attribute::make(
  40. set: fn ($value) => json_encode($value),
  41. );
  42. }
  43. public function collection()
  44. {
  45. return $this->belongsTo(Collection::class);
  46. }
  47. public function getPath()
  48. {
  49. return Storage::disk($this->collection->disk)->path($this->server_path . $this->uuid . '.' . $this->collection->ext);
  50. }
  51. public function getModifiedPath()
  52. {
  53. return Storage::disk(app()->collection->disk)->path(app()->file->server_path . app()->file->uuid . '-modified.' . app()->collection->ext);
  54. }
  55. }