ProductReviewAttachment.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace Webkul\Product\Models;
  3. use Illuminate\Database\Eloquent\Factories\Factory;
  4. use Illuminate\Database\Eloquent\Factories\HasFactory;
  5. use Illuminate\Database\Eloquent\Model;
  6. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  7. use Illuminate\Support\Facades\Storage;
  8. use Webkul\Product\Contracts\ProductReviewAttachment as ProductReviewAttachmentContract;
  9. use Webkul\Product\Database\Factories\ProductReviewAttachmentFactory;
  10. class ProductReviewAttachment extends Model implements ProductReviewAttachmentContract
  11. {
  12. use HasFactory;
  13. /**
  14. * Timestamp false
  15. *
  16. * @var bool
  17. */
  18. public $timestamps = false;
  19. /**
  20. * Define fillable property
  21. *
  22. * @var array
  23. */
  24. protected $fillable = [
  25. 'path',
  26. 'review_id',
  27. 'type',
  28. 'mime_type',
  29. ];
  30. /**
  31. * The accessors to append to the model's array form.
  32. *
  33. * @var array
  34. */
  35. protected $appends = ['url'];
  36. /**
  37. * Get the review that owns the image.
  38. */
  39. public function review(): BelongsTo
  40. {
  41. return $this->belongsTo(ProductReviewProxy::modelClass());
  42. }
  43. /**
  44. * Get image url for the review image.
  45. */
  46. public function url(): string
  47. {
  48. return Storage::url($this->path);
  49. }
  50. /**
  51. * Get image url for the review image.
  52. */
  53. public function getUrlAttribute(): string
  54. {
  55. return $this->url();
  56. }
  57. /**
  58. * Create a new factory instance for the model.
  59. */
  60. protected static function newFactory(): Factory
  61. {
  62. return ProductReviewAttachmentFactory::new();
  63. }
  64. }