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.

71 lines
1.4 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
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Casts\Attribute;
  4. use Illuminate\Database\Eloquent\Factories\HasFactory;
  5. use Illuminate\Database\Eloquent\Model;
  6. use Illuminate\Database\Eloquent\SoftDeletes;
  7. class Collection extends Model
  8. {
  9. use HasFactory, SoftDeletes;
  10. protected $fillable = [
  11. "name",
  12. "path",
  13. "public",
  14. "disk",
  15. "count",
  16. "tmp_support",
  17. "remove_tmp_time",
  18. "max_file_size",
  19. "min_file_size",
  20. "max_width",
  21. "min_width",
  22. "max_height",
  23. "min_height",
  24. "alt_required",
  25. "description_required",
  26. "exts",
  27. "ext",
  28. "mimetypes",
  29. "model",
  30. "expire_date",
  31. ];
  32. protected $casts = [
  33. 'exts' => 'array',
  34. 'mimetypes' => 'array',
  35. ];
  36. public function files()
  37. {
  38. return $this->hasMany(File::class);
  39. }
  40. protected function exts(): Attribute
  41. {
  42. return Attribute::make(
  43. set: fn ($value) => json_encode($value),
  44. );
  45. }
  46. protected function mimetypes(): Attribute
  47. {
  48. return Attribute::make(
  49. set: fn ($value) => json_encode($value),
  50. );
  51. }
  52. public function getExts()
  53. {
  54. return implode(",", app()->collection->exts);
  55. }
  56. public function getMimeTypes()
  57. {
  58. return implode(",", app()->collection->mimetypes);
  59. }
  60. }