initial commit
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\HasUuid;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
#[Fillable(['user_id', 'machine_id', 'slot_start', 'slot_end', 'booking_fee', 'reserved_amount', 'penalty_amount', 'status', 'cancelled_at', 'penalty_applied_at'])]
|
||||
class Booking extends Model
|
||||
{
|
||||
use HasUuid;
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'slot_start' => 'datetime',
|
||||
'slot_end' => 'datetime',
|
||||
'booking_fee' => 'decimal:2',
|
||||
'reserved_amount' => 'decimal:2',
|
||||
'penalty_amount' => 'decimal:2',
|
||||
'status' => 'string',
|
||||
'cancelled_at' => 'datetime',
|
||||
'penalty_applied_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function machine(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Machine::class);
|
||||
}
|
||||
|
||||
public function washes(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Wash::class);
|
||||
}
|
||||
|
||||
public function isCancellable(): bool
|
||||
{
|
||||
return in_array($this->status, ['pending', 'confirmed'], true)
|
||||
&& $this->slot_start->isFuture();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user