File.php 708 B

12345678910111213141516171819202122232425262728293031323334353637
  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. ];
  17. protected $appends = [
  18. 'name',
  19. ];
  20. public function user(): BelongsTo
  21. {
  22. return $this->belongsTo(User::class);
  23. }
  24. public function name(): Attribute
  25. {
  26. return Attribute::make(
  27. get: fn () => $this->original_name ?? '',
  28. );
  29. }
  30. }