initial commit
This commit is contained in:
48
app/Models/Event.php
Normal file
48
app/Models/Event.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\EventStatus;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Event extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'client_id', 'title', 'description', 'event_type',
|
||||
'start_time', 'end_time', 'location', 'is_priority',
|
||||
'is_all_day', 'status', 'color', 'notes',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'start_time' => 'datetime',
|
||||
'end_time' => 'datetime',
|
||||
'is_priority' => 'boolean',
|
||||
'is_all_day' => 'boolean',
|
||||
'status' => EventStatus::class,
|
||||
];
|
||||
|
||||
public function client(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Client::class);
|
||||
}
|
||||
|
||||
public function scopeUpcoming($query, int $hours = 24)
|
||||
{
|
||||
return $query->where('start_time', '>=', now())
|
||||
->where('start_time', '<=', now()->addHours($hours))
|
||||
->where('status', '!=', EventStatus::Completed->value)
|
||||
->where('status', '!=', EventStatus::Cancelled->value);
|
||||
}
|
||||
|
||||
public function scopeToday($query)
|
||||
{
|
||||
return $query->whereDate('start_time', today());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user