Files
tehnobox/app/Models/HomeSlide.php
ssww23 93a655235a
Some checks failed
Deploy / deploy (push) Has been cancelled
Initial commit
2026-03-10 00:55:37 +03:00

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, '/');
}
}