| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- /*
- * Car — модель автомобиля в каталоге.
- *
- * Создана: 2026-05-06 | Таблица: cars (миграция: 2026_05_06_151148_create_cars_table.php)
- * $fillable — все поля, кроме id/timestamps (mass assignment через Car::create/update)
- * $casts — автоматическое преобразование типов: boolean-поля, JSON-массивы (options, photos_gallery)
- * Акцессоры getXxxAttribute() — виртуальные поля для отображения меток в шаблонах
- */
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- class Car extends Model
- {
- protected $fillable = [
- 'status', 'condition', 'make', 'model', 'generation', 'year',
- 'vin', 'plate', 'body_type', 'doors', 'color_exterior', 'color_interior',
- 'engine_type', 'engine_volume', 'engine_power_hp', 'transmission', 'drive',
- 'mileage_km', 'steering', 'owners_count', 'customs_cleared', 'pts', 'accident_free',
- 'price_usd', 'price_rub', 'price_vladivostok', 'price_moscow', 'price_negotiable',
- 'country_origin', 'city', 'platform', 'options', 'title', 'description',
- 'photo_main', 'photos_gallery',
- ];
- protected $casts = [
- 'customs_cleared' => 'boolean',
- 'accident_free' => 'boolean',
- 'price_negotiable' => 'boolean',
- 'photos_gallery' => 'array',
- 'options' => 'array',
- ];
- // Акцессор: возвращает читаемую русскую метку статуса для шаблонов ($car->status_label)
- public function getStatusLabelAttribute(): string
- {
- return match ($this->status) {
- 'active' => 'Активен',
- 'sold' => 'Продан',
- 'draft' => 'Черновик',
- default => $this->status,
- };
- }
- // Акцессор: возвращает "Новый" или "Б/У" ($car->condition_label)
- public function getConditionLabelAttribute(): string
- {
- return $this->condition === 'new' ? 'Новый' : 'Б/У';
- }
- }
|