first commit
This commit is contained in:
74
app/Models/Articles.php
Normal file
74
app/Models/Articles.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Scopes\ActiveScope;
|
||||
use App\Models\User;
|
||||
use App\Traits\CreatedUpdatedBy;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Articles extends Model
|
||||
{
|
||||
use HasFactory, CreatedUpdatedBy;
|
||||
|
||||
protected $primaryKey = 'article_id';
|
||||
public $timestamps = true;
|
||||
protected $fillable = [
|
||||
'parent_article',
|
||||
'title',
|
||||
'subtitle',
|
||||
'alias',
|
||||
'description',
|
||||
'additional_description',
|
||||
'cover_photo',
|
||||
'thumb',
|
||||
'display_order',
|
||||
'status',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'seo_keywords',
|
||||
'seo_title',
|
||||
'seo_descriptions',
|
||||
'og_tags',
|
||||
'createdby',
|
||||
'updatedby',
|
||||
|
||||
];
|
||||
|
||||
protected $appends = ['status_name'];
|
||||
|
||||
protected function getStatusNameAttribute()
|
||||
{
|
||||
return $this->status == 1 ? '<span class="badge text-bg-success-soft"> Active </span>' : '<span class="badge text-bg-danger-soft">Inactive</span>';
|
||||
}
|
||||
|
||||
protected static function booted(): void{
|
||||
static::AddGlobalScope(new ActiveScope);
|
||||
}
|
||||
|
||||
protected function createdBy(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn($value) => User::find($value) ? User::find($value)->name : '',
|
||||
);
|
||||
}
|
||||
|
||||
protected function updatedBy(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn($value) => User::find($value) ? User::find($value)->name : '',
|
||||
);
|
||||
}
|
||||
|
||||
public function parent()
|
||||
{
|
||||
return $this->belongsTo(Articles::class, 'parent_article')->where('status', 1);
|
||||
}
|
||||
|
||||
public function children()
|
||||
{
|
||||
return $this->hasMany(Articles::class, 'parent_article')->where('status', 1);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user