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.

73 lines
1.5 KiB

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