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.

60 lines
1.5 KiB

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. "collection_id",
  28. "published_at",
  29. ];
  30. protected $casts = [
  31. 'alts' => 'array',
  32. ];
  33. protected function alts(): Attribute
  34. {
  35. return Attribute::make(
  36. set: fn ($value) => json_encode($value),
  37. );
  38. }
  39. // public function rules(): array
  40. // {
  41. // return [
  42. // "image" => [
  43. // "mimes:" . app()->collection->getExts(),
  44. // "mimetypes:" . app()->collection->getMimeTypes(),
  45. // "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,
  46. // "max:" . app()->collection->max_size,
  47. // "min:" . app()->collection->min_size,
  48. // ],
  49. // ];
  50. // }
  51. }