49 lines
921 B
PHP
49 lines
921 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Str;
|
|
|
|
class Template extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'templates';
|
|
|
|
protected $fillable = [
|
|
'nama_template',
|
|
'harga',
|
|
'foto',
|
|
'paket',
|
|
'form',
|
|
'kategori_id',
|
|
];
|
|
|
|
protected $casts = [
|
|
'form' => 'array',
|
|
'harga' => 'decimal:2',
|
|
];
|
|
|
|
protected $appends = ['slug'];
|
|
|
|
// Relasi ke Kategori
|
|
public function kategori()
|
|
{
|
|
return $this->belongsTo(Kategori::class, 'kategori_id');
|
|
}
|
|
|
|
// Relasi ke Pelanggan
|
|
public function pelanggans()
|
|
{
|
|
return $this->hasMany(Pelanggan::class, 'template_id');
|
|
}
|
|
|
|
// Accessor untuk slug
|
|
public function getSlugAttribute()
|
|
{
|
|
return Str::slug($this->nama_template);
|
|
}
|
|
}
|