ProductDownloadableSample.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace Webkul\Product\Models;
  3. use Illuminate\Support\Facades\Storage;
  4. use Webkul\Core\Eloquent\TranslatableModel;
  5. use Webkul\Product\Contracts\ProductDownloadableSample as ProductDownloadableSampleContract;
  6. class ProductDownloadableSample extends TranslatableModel implements ProductDownloadableSampleContract
  7. {
  8. public $translatedAttributes = ['title'];
  9. protected $fillable = [
  10. 'url',
  11. 'file',
  12. 'file_name',
  13. 'type',
  14. 'sort_order',
  15. 'product_id',
  16. ];
  17. protected $with = ['translations'];
  18. /**
  19. * Get the product that owns the image.
  20. */
  21. public function product()
  22. {
  23. return $this->belongsTo(ProductProxy::modelClass());
  24. }
  25. /**
  26. * Get image url for the file.
  27. */
  28. public function file_url()
  29. {
  30. return Storage::url($this->file);
  31. }
  32. /**
  33. * Get image url for the file.
  34. */
  35. public function getFileUrlAttribute()
  36. {
  37. return $this->file_url();
  38. }
  39. /**
  40. * @return array
  41. */
  42. public function toArray()
  43. {
  44. $array = parent::toArray();
  45. $translation = $this->translate(core()->getRequestedLocaleCode());
  46. $array['title'] = $translation ? $translation->title : '';
  47. $array['file_url'] = $this->file ? Storage::url($this->file) : null;
  48. return $array;
  49. }
  50. }