84 lines
1.8 KiB
PHP
84 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Booking extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'bookings'; // Nama tabel
|
|
|
|
protected $fillable = [
|
|
'customer_id',
|
|
'produk',
|
|
'paket',
|
|
'tanggal_pemotretan',
|
|
'durasi_booking',
|
|
'payment_method',
|
|
'total_harga',
|
|
'dp',
|
|
'status',
|
|
'keterangan',
|
|
'bukti_transfer',
|
|
'pelunasan',
|
|
'bukti_pelunasan',
|
|
];
|
|
|
|
/**
|
|
* Relasi ke tabel Customer (misalnya tabel `customers`).
|
|
*/
|
|
public function customer()
|
|
{
|
|
return $this->belongsTo(User::class, 'customer_id'); // Merujuk ke tabel `users`
|
|
}
|
|
|
|
/**
|
|
* Menentukan apakah booking disetujui.
|
|
*/
|
|
public function isApproved()
|
|
{
|
|
return $this->status === 'approved';
|
|
}
|
|
|
|
/**
|
|
* Menentukan apakah booking ditolak.
|
|
*/
|
|
public function isDeclined()
|
|
{
|
|
return $this->status === 'declined';
|
|
}
|
|
|
|
/**
|
|
* Menentukan apakah booking masih pending.
|
|
*/
|
|
public function isPending()
|
|
{
|
|
return $this->status === 'pending';
|
|
}
|
|
|
|
public function photos()
|
|
{
|
|
return $this->hasMany(Photo::class); // Relasi ke photos
|
|
}
|
|
|
|
/**
|
|
* Menambahkan properti 'color' berdasarkan status booking
|
|
*/
|
|
public function getColorAttribute()
|
|
{
|
|
switch ($this->status) {
|
|
case 'approved':
|
|
return '#dc3545'; // Merah
|
|
case 'pending':
|
|
return '#ffc107'; // Kuning
|
|
case 'declined':
|
|
return '#007bff'; // Biru
|
|
default:
|
|
return '#28a745'; // Hijau jika tidak ada status yang cocok
|
|
}
|
|
}
|
|
}
|