|
|
@@ -13,6 +13,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
+use Illuminate\Support\Facades\Storage;
|
|
|
|
|
|
#[ScopedBy([YearScope::class])]
|
|
|
class Product extends Model
|
|
|
@@ -49,8 +50,16 @@ class Product extends Model
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- protected $appends = ['product_price', 'installation_price', 'total_price',
|
|
|
- 'product_price_txt', 'installation_price_txt', 'total_price_txt',];
|
|
|
+ protected $appends = [
|
|
|
+ 'product_price',
|
|
|
+ 'installation_price',
|
|
|
+ 'total_price',
|
|
|
+ 'product_price_txt',
|
|
|
+ 'installation_price_txt',
|
|
|
+ 'total_price_txt',
|
|
|
+ 'image'
|
|
|
+ ];
|
|
|
+
|
|
|
protected function productPrice(): Attribute
|
|
|
{
|
|
|
return Attribute::make(
|
|
|
@@ -102,7 +111,6 @@ class Product extends Model
|
|
|
{
|
|
|
return Attribute::make(
|
|
|
get: fn($value) => $this->article . ', №' . $this->nomenclature_number,
|
|
|
-// get: fn($value) => (string) $this->name_tz . ' (арт.' . $this->article . ', №' . $this->nomenclature_number . ', ' . $this->year . 'г, ' . $this->product_price_txt . ')',
|
|
|
);
|
|
|
}
|
|
|
|
|
|
@@ -134,6 +142,18 @@ class Product extends Model
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ public function image(): Attribute
|
|
|
+ {
|
|
|
+ if(file_exists(public_path() . '/images/main/' . $this->article . '.0000.0000.jpg')) {
|
|
|
+
|
|
|
+ $path = url('/images/main/' . $this->article . '.0000.0000.jpg');
|
|
|
+ } else {
|
|
|
+ $path = '';
|
|
|
+ }
|
|
|
+ return Attribute::make(
|
|
|
+ get: fn() => $path,
|
|
|
+ );
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|