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.

97 lines
2.6 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
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. class Collection extends Model
  10. {
  11. use HasFactory, SoftDeletes, Validatable, ValidationMaker;
  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. public function rules(): array
  49. {
  50. return [
  51. 'name' => ['max:100', 'Required', 'string', 'unique:collections,name'],
  52. "path" => ['max:255', 'nullable', 'string'],
  53. "public" => ['nullable', 'boolean'],
  54. "disk" => ['required', 'string', 'max:255'],
  55. "count" => ['required', 'numeric', 'max:255'],
  56. "tmp_support" => ['required', 'boolean'],
  57. "remove_tmp_time" => ['date_format:Y-m-d H:i:s', 'nullable'],
  58. "max_file_size" => ['nullable', 'numeric'],
  59. "min_file_size" => ['nullable', 'numeric'],
  60. "max_width" => ['nullable', 'numeric'],
  61. "min_width" => ['nullable', 'numeric'],
  62. "max_height" => ['nullable', 'numeric'],
  63. "min_height" => ['nullable', 'numeric'],
  64. "alt_required" => ['required', 'boolean'],
  65. "description_required"=> ['required','boolean'],
  66. "exts" => ['nullable'],
  67. "ext" => ['string','max:100','nullable'],
  68. "mimetypes"=> ['nullable'],
  69. "expire_date" => ['date_format:Y-m-d H:i:s','nullable'],
  70. ];
  71. }
  72. protected function mimetypes(): Attribute
  73. {
  74. return Attribute::make(
  75. set: fn ($value) => json_encode($value),
  76. );
  77. }
  78. public function getExts()
  79. {
  80. return implode(",", app()->collection->exts);
  81. }
  82. public function getMimeTypes()
  83. {
  84. return implode(",", app()->collection->mimetypes);
  85. }
  86. }