111 lines
2.9 KiB
PHP
111 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Helpers\PriceHelper;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Spatie\Translatable\HasTranslations;
|
|
|
|
class CmsProject extends Model
|
|
{
|
|
use HasFactory, HasTranslations;
|
|
|
|
protected $table = 'cms_projects';
|
|
|
|
protected $fillable = [
|
|
'slug',
|
|
'title',
|
|
'location',
|
|
'status',
|
|
'launch_date',
|
|
'price_from_aed',
|
|
'currency',
|
|
'image',
|
|
'highlights',
|
|
'quick_facts',
|
|
'investment_case',
|
|
'gallery',
|
|
'location_info',
|
|
'contact',
|
|
'investor_trust',
|
|
'furniture_benefit',
|
|
'is_published',
|
|
'order',
|
|
];
|
|
|
|
/** @var array<string> */
|
|
public array $translatable = [
|
|
'title',
|
|
'location',
|
|
'highlights',
|
|
'investment_case',
|
|
'location_info',
|
|
'contact',
|
|
'investor_trust',
|
|
'furniture_benefit',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'launch_date' => 'date',
|
|
'price_from_aed' => 'integer',
|
|
'highlights' => 'array',
|
|
'quick_facts' => 'array',
|
|
'investment_case' => 'array',
|
|
'gallery' => 'array',
|
|
'location_info' => 'array',
|
|
'contact' => 'array',
|
|
'is_published' => 'boolean',
|
|
'order' => 'integer',
|
|
];
|
|
}
|
|
|
|
public function scopePublished(Builder $query): Builder
|
|
{
|
|
return $query->where('is_published', true);
|
|
}
|
|
|
|
public function scopeOrdered(Builder $query): Builder
|
|
{
|
|
return $query->orderBy('order')->orderByDesc('launch_date');
|
|
}
|
|
|
|
public function getFormattedPrice(string $prefix = 'ab'): string
|
|
{
|
|
if (! $this->price_from_aed) {
|
|
return '';
|
|
}
|
|
|
|
return PriceHelper::formatAed($this->price_from_aed, $prefix);
|
|
}
|
|
|
|
/**
|
|
* Returns an array compatible with the existing Blade views
|
|
* (immobilien.blade.php and immobilien-show.blade.php).
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toFrontendArray(): array
|
|
{
|
|
return [
|
|
'slug' => $this->slug,
|
|
'title' => $this->title,
|
|
'location' => $this->location,
|
|
'status' => $this->status,
|
|
'launch_date' => $this->launch_date?->format('d.m.Y'),
|
|
'price_from' => $this->getFormattedPrice(),
|
|
'image' => $this->image,
|
|
'highlights' => $this->highlights ?? [],
|
|
'quick_facts' => $this->quick_facts ?? [],
|
|
'investment_case' => $this->investment_case ?? [],
|
|
'gallery' => $this->gallery ?? [],
|
|
'location_info' => $this->location_info ?? [],
|
|
'contact' => $this->contact ?? [],
|
|
'investor_trust' => $this->investor_trust ?? [],
|
|
'furniture_benefit' => $this->furniture_benefit ?? [],
|
|
];
|
|
}
|
|
}
|