This commit is contained in:
69
app/Models/HomeSlide.php
Normal file
69
app/Models/HomeSlide.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?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, '/');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user