новости

This commit is contained in:
2026-03-22 17:28:03 +04:00
parent 573e2afbbf
commit 324d1ad75c
11 changed files with 594 additions and 6 deletions
+48
View File
@@ -0,0 +1,48 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;
class News extends Model
{
protected $fillable = [
'title',
'body',
'image_path',
'sort_order',
'is_published',
'created_by_account_id',
'created_by_username',
];
protected function casts(): array
{
return [
'is_published' => 'bool',
];
}
public function scopeOrdered(Builder $query): Builder
{
return $query
->orderBy('sort_order')
->orderByDesc('id');
}
public function scopePublished(Builder $query): Builder
{
return $query->where('is_published', true);
}
public function getImageUrlAttribute(): ?string
{
if (! $this->image_path) {
return null;
}
return Storage::disk('public')->url($this->image_path);
}
}