first commit
This commit is contained in:
84
app/Models/Preparationclasses.php
Normal file
84
app/Models/Preparationclasses.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
|
||||
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 Preparationclasses extends Model
|
||||
{
|
||||
use HasFactory, CreatedUpdatedBy;
|
||||
|
||||
protected $primaryKey = 'preparationclass_id';
|
||||
public $timestamps = true;
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'alias',
|
||||
'parent_preparationclass',
|
||||
'description',
|
||||
'additional_description',
|
||||
'intro',
|
||||
'image',
|
||||
'thumb',
|
||||
'cover',
|
||||
'remarks',
|
||||
'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 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(Preparationclasses::class, 'parent_preparationclass');
|
||||
}
|
||||
|
||||
public function children()
|
||||
{
|
||||
return $this->hasMany(Preparationclasses::class, 'parent_preparationclass')
|
||||
->where('status', 1)
|
||||
->orderBy('display_order', 'asc');
|
||||
}
|
||||
|
||||
public function offerClasses()
|
||||
{
|
||||
return $this->hasMany(Preparationclassoffers::class, 'preparationclasses_id')
|
||||
->where('status', 1);
|
||||
}
|
||||
|
||||
public function testimonials()
|
||||
{
|
||||
return $this->hasMany(Preparationclasstestimonials::class, 'preparationclasses_id')
|
||||
->where('status', 1);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user