File.php 633 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Casts\Attribute;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  6. class File extends Model
  7. {
  8. protected $fillable = [
  9. 'user_id',
  10. 'original_name',
  11. 'mime_type',
  12. 'path',
  13. 'link',
  14. ];
  15. protected $appends = [
  16. 'name',
  17. ];
  18. public function user(): BelongsTo
  19. {
  20. return $this->belongsTo(User::class);
  21. }
  22. public function name(): Attribute
  23. {
  24. return Attribute::make(
  25. get: fn () => $this->original_name ?? '',
  26. );
  27. }
  28. }