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.

55 lines
1.0 KiB

3 years ago
  1. <?php
  2. namespace App\Models;
  3. use App\Models\Traits\Validatable;
  4. use Illuminate\Database\Eloquent\Casts\Attribute;
  5. use Illuminate\Database\Eloquent\Factories\HasFactory;
  6. use Illuminate\Database\Eloquent\Model;
  7. use Illuminate\Database\Eloquent\SoftDeletes;
  8. use Illuminate\Support\Str;
  9. class File extends Model
  10. {
  11. use HasFactory, SoftDeletes;
  12. protected $primaryKey = 'uuid';
  13. protected $fillable = [
  14. "uuid",
  15. "original_name",
  16. "ext",
  17. "memetype",
  18. "width",
  19. "server_path",
  20. "height",
  21. "file_size",
  22. "sort",
  23. "alts",
  24. "description",
  25. "user_id",
  26. "ip",
  27. "collection_id",
  28. "published_at",
  29. ];
  30. protected $casts = [
  31. 'alts' => 'array',
  32. ];
  33. protected function uuid(): Attribute
  34. {
  35. return Attribute::make(
  36. set: fn ($value) => Str::uuid(),
  37. );
  38. }
  39. protected function alts(): Attribute
  40. {
  41. return Attribute::make(
  42. set: fn ($value) => json_encode($value),
  43. );
  44. }
  45. }