ProductVideo.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace Webkul\Product\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Support\Facades\Storage;
  5. use Webkul\Product\Contracts\ProductVideo as ProductVideoContract;
  6. class ProductVideo extends Model implements ProductVideoContract
  7. {
  8. /**
  9. * Timestamps.
  10. *
  11. * @param bool
  12. */
  13. public $timestamps = false;
  14. /**
  15. * Fillable.
  16. *
  17. * @param array
  18. */
  19. protected $fillable = [
  20. 'type',
  21. 'path',
  22. 'product_id',
  23. 'position',
  24. ];
  25. /**
  26. * The accessors to append to the model's array form.
  27. *
  28. * @var array
  29. */
  30. protected $appends = ['url'];
  31. /**
  32. * Get the product that owns the image.
  33. *
  34. * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
  35. */
  36. public function product()
  37. {
  38. return $this->belongsTo(ProductProxy::modelClass());
  39. }
  40. /**
  41. * Get image url for the product image.
  42. *
  43. * @return string
  44. */
  45. public function url()
  46. {
  47. return Storage::url($this->path);
  48. }
  49. /**
  50. * Get image url for the product image.
  51. *
  52. * @return string
  53. */
  54. public function getUrlAttribute()
  55. {
  56. return $this->url();
  57. }
  58. /**
  59. * Is custom attribute.
  60. *
  61. * @param string $attribute
  62. * @return bool
  63. */
  64. public function isCustomAttribute($attribute)
  65. {
  66. return $this->attribute_family->custom_attributes->pluck('code')->contains($attribute);
  67. }
  68. }