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.6 KiB

3 years ago
3 years ago
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, Validatable;
  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. public function rules(): array
  46. {
  47. return [
  48. "image" => [
  49. "mimes:" . app()->collection->getExts(),
  50. "mimetypes:" . app()->collection->getMimeTypes(),
  51. "dimensions:min_width=" . app()->collection->min_width . ",min_height=" . app()->collection->min_height . ',max_width=' . app()->collection->max_width . ',max_height='. app()->collection->max_height,
  52. "max:" . app()->collection->max_size,
  53. "min:" . app()->collection->min_size,
  54. ],
  55. ];
  56. }
  57. }