| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace Webkul\Product\Models;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Facades\Storage;
- use Illuminate\Support\Str;
- use Webkul\Product\Contracts\ProductImage as ProductImageContract;
- class ProductImage extends Model implements ProductImageContract
- {
- /**
- * Timestamp.
- *
- * @var bool
- */
- public $timestamps = false;
- /**
- * Fillable.
- *
- * @var array
- */
- protected $fillable = [
- 'type',
- 'path',
- 'product_id',
- 'position',
- ];
- /**
- * The accessors to append to the model's array form.
- *
- * @var array
- */
- protected $appends = ['url'];
- /**
- * Get the product that owns the image.
- *
- * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
- */
- public function product()
- {
- return $this->belongsTo(ProductProxy::modelClass());
- }
- /**
- * Get image url for the product image.
- *
- * @return string
- */
- public function url()
- {
- // Imported product images may store a remote/absolute URL directly in
- // the `path` column; return it verbatim instead of prefixing the local
- // storage path.
- if (is_string($this->path) && Str::startsWith($this->path, ['http://', 'https://'])) {
- return $this->path;
- }
- return Storage::url($this->path);
- }
- /**
- * Get image url for the product image.
- *
- * @return string
- */
- public function getUrlAttribute()
- {
- return $this->url();
- }
- /**
- * Is custom attribute.
- *
- * @param string $key
- * @return bool
- */
- public function isCustomAttribute($attribute)
- {
- return $this->attribute_family->custom_attributes->pluck('code')->contains($attribute);
- }
- }
|