/
hikqri
/
up
Обзор
Документация
Войти
/
hikqri
/
up
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
app/Models/Product.php
57 строк
1 KB
Myckaa
first_commit
26 июн 2026, 18:36
26 июн 2026, 18:36
8095503
Код
Авторство
О чём код?
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; class Product extends Model { protected $fillable = [ 'category_id', 'name', 'slug', 'description', 'price', 'image', 'rating', 'reviews_count', 'is_featured', 'is_recommended', ]; protected $casts = [ 'price' => 'decimal:2', 'rating' => 'decimal:1', 'is_featured' => 'boolean', 'is_recommended' => 'boolean', ]; public function category() { return $this->belongsTo(Category::class); } public function formattedPrice(): string { return number_format($this->price, 0, '.', ' ') . ' ₽'; } public function imageUrl(): ?string { if (!$this->image) { return null; } $image = str_replace('\\', '/', $this->image); if (str_starts_with($image, 'products/')) { return asset('storage/' . $image); } if (!str_starts_with($image, 'uploads/')) { return asset('uploads/products/' . basename($image)); } return asset($image); } }