// SYSTEM PANEL //
[ROOT]
/
mnt
/
pleskStorage
/
vhosts
/
kodsolutions.net
/
subdomains
/
go-rent.kodsolutions.net
/
app
/
Models
/
Car
[ PARENT ]
EDIT :: Car.php
<?php namespace App\Models\Car; use App\Models\Booking\Order; use App\Models\Model; use App\Models\Office\Office; use App\Models\User; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; use Spatie\Translatable\HasTranslations; class Car extends Model implements HasMedia { use HasFactory; use HasTranslations; use InteractsWithMedia; public $appends = ['image_path', 'url']; public $translatable = [ 'title', 'description', 'sub_title', ]; protected $fillable = [ 'active', 'best_deal', 'sponsored', 'featured', 'in_home', 'status_id', 'expired_at', 'title', 'sub_title', 'description', 'tags', 'keywords', 'slug', 'plate_number', 'code', 'price', 'special_price', 'discount', 'accept_immediately', 'immediately_time', 'seating_capacity', 'daily_price', 'weekly_price', 'monthly_price', 'daily_mileage_limit', 'excess_mileage_fee', 'is_available', 'no_views', 'position', 'payment_method', 'branch_id', 'office_id', 'tags', 'keywords', 'image', 'vehicle_type_id', // 'sedan', 'suv', 'hatchback', 'van', 'pickup', 'luxury', 'other' 'brand_id', // brand 'model_id', // brand 'year_id', // year 'category_id', // 'economy', 'standard', 'premium', 'luxury', 'suv', 'van' 'fuel_type_id', // 'petrol', 'diesel', 'hybrid', 'electric' 'transmission_id', // 'manual', 'automatic' 'insurance_type_id', // 'comprehensive', 'third_party' 'color_id', // 'comprehensive', 'third_party' 'city_id', 'area_id', 'branch_id', 'office_id', 'car_license', ]; public function setTagsAttribute($value) { $this->attributes['tags'] = json_encode($value); } public function getTagsAttribute($value) { return json_decode($value); } public function setKeywordsAttribute($value) { $this->attributes['keywords'] = json_encode($value); } public function getKeywordsAttribute($value) { return json_decode($value); } public function category(): BelongsTo { return $this->belongsTo(Category::class, 'category_id'); } public function status(): BelongsTo { return $this->belongsTo(Category::class, 'status_id'); } public function owner(): BelongsTo { return $this->belongsTo(User::class, 'user_id'); } public function type(): BelongsTo { return $this->belongsTo(Category::class, 'type_id'); } public function city(): BelongsTo { return $this->belongsTo(\App\Models\City::class, 'city_id'); } public function getUrlAttribute() { return route('website.cars.show', [ 'locale' => app()->getLocale(), 'code' => $this->code, 'slug' => $this->slug, ]); } public function getPriceAfterAttribute() { return $this->price - ($this->discount > 0 ? round($this->price * $this->discount / 100, 2) : 0); } public function getImagesAttribute() { $images = []; $files = $this->getMedia('images'); if (!empty($files)) { foreach ($files as $file) { array_push($images, $file->getFullUrl()); } } return $images; } public function brand(): BelongsTo { return $this->belongsTo(Category::class, 'brand_id'); } public function model(): BelongsTo { return $this->belongsTo(Category::class, 'model_id'); } public function year(): BelongsTo { return $this->belongsTo(Category::class, 'year_id'); } public function vehicleType(): BelongsTo { return $this->belongsTo(Category::class, 'vehicle_type_id'); } public function fuelType(): BelongsTo { return $this->belongsTo(Category::class, 'fuel_type_id'); } public function transmission(): BelongsTo { return $this->belongsTo(Category::class, 'transmission_id'); } public function color(): BelongsTo { return $this->belongsTo(Category::class, 'color_id'); } public function insuranceType(): BelongsTo { return $this->belongsTo(Category::class, 'insurance_type_id'); } public function branch(): BelongsTo { return $this->belongsTo(Category::class, 'branch_id'); } public function office(): BelongsTo { return $this->belongsTo(Office::class, 'office_id'); } public function rentals(): HasMany { return $this->hasMany(CarRental::class); } public function orders(): HasMany { return $this->hasMany(Order::class); } public function latestOrder() { return $this->hasOne(Order::class, 'car_id')->latest(); } public function favorites(): BelongsToMany { return $this->belongsToMany(User::class, 'favourites', 'car_id', 'user_id'); } public function getIsFavouriteAttribute() { $favourite = 0; if ( auth()->user() && Favourite::whereStatus(1)->where('cart_id', $this->id) ->where('user_id', auth()->user()->id)->count() > 0 ) { $favourite = 1; } return $favourite; } }
SAVE
CANCEL