70 lines
1.5 KiB
PHP
70 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Str;
|
|
|
|
class HomeSlide extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'zone',
|
|
'title',
|
|
'show_title',
|
|
'subtitle',
|
|
'show_subtitle',
|
|
'button_text',
|
|
'button_url',
|
|
'show_button',
|
|
'image_path',
|
|
'sort_order',
|
|
'is_active',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'show_title' => 'boolean',
|
|
'show_subtitle' => 'boolean',
|
|
'show_button' => 'boolean',
|
|
'sort_order' => 'integer',
|
|
'is_active' => 'boolean',
|
|
];
|
|
}
|
|
|
|
public function scopeActive($query)
|
|
{
|
|
return $query->where('is_active', true);
|
|
}
|
|
|
|
public function scopeForZone($query, string $zone)
|
|
{
|
|
return $query->where('zone', $zone);
|
|
}
|
|
|
|
public function scopeOrdered($query)
|
|
{
|
|
return $query->orderBy('sort_order')->orderBy('id');
|
|
}
|
|
|
|
public function getImageUrlAttribute(): ?string
|
|
{
|
|
if (!$this->image_path) {
|
|
return null;
|
|
}
|
|
|
|
if (Str::startsWith($this->image_path, ['http://', 'https://', '/'])) {
|
|
return $this->image_path;
|
|
}
|
|
|
|
if (Str::startsWith($this->image_path, 'uploads/')) {
|
|
return asset($this->image_path);
|
|
}
|
|
|
|
return '/storage/' . ltrim($this->image_path, '/');
|
|
}
|
|
}
|