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.

61 lines
1.5 KiB

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 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. "mimetype",
  18. "width",
  19. "server_path",
  20. "height",
  21. "file_size",
  22. "sort",
  23. "alts",
  24. "description",
  25. "user_id",
  26. "ip",
  27. "model_id",
  28. "collection_id",
  29. "published_at",
  30. ];
  31. protected $casts = [
  32. 'alts' => 'array',
  33. ];
  34. protected function alts(): Attribute
  35. {
  36. return Attribute::make(
  37. set: fn ($value) => json_encode($value),
  38. );
  39. }
  40. // public function rules(): array
  41. // {
  42. // return [
  43. // "image" => [
  44. // "mimes:" . app()->collection->getExts(),
  45. // "mimetypes:" . app()->collection->getMimeTypes(),
  46. // "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,
  47. // "max:" . app()->collection->max_size,
  48. // "min:" . app()->collection->min_size,
  49. // ],
  50. // ];
  51. // }
  52. }