File.php 802 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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\Relations\BelongsTo;
  7. class File extends Model
  8. {
  9. use HasFactory;
  10. protected $fillable = [
  11. 'user_id',
  12. 'original_name',
  13. 'mime_type',
  14. 'path',
  15. 'link',
  16. 'is_generated',
  17. ];
  18. protected $appends = [
  19. 'name',
  20. ];
  21. protected $casts = [
  22. 'is_generated' => 'boolean',
  23. ];
  24. public function user(): BelongsTo
  25. {
  26. return $this->belongsTo(User::class);
  27. }
  28. public function name(): Attribute
  29. {
  30. return Attribute::make(
  31. get: fn () => $this->original_name ?? '',
  32. );
  33. }
  34. }