first&last
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\EquipmentCondition;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Equipment extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'equipment';
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'serial_number',
|
||||
'inventory_number',
|
||||
'category_id',
|
||||
'client_id',
|
||||
'purchase_date',
|
||||
'warranty_until',
|
||||
'condition',
|
||||
'notes',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'purchase_date' => 'date',
|
||||
'warranty_until' => 'date',
|
||||
'condition' => EquipmentCondition::class,
|
||||
];
|
||||
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(EquipmentCategory::class, 'category_id');
|
||||
}
|
||||
|
||||
public function client(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'client_id');
|
||||
}
|
||||
|
||||
public function requests(): HasMany
|
||||
{
|
||||
return $this->hasMany(ServiceRequest::class, 'equipment_id');
|
||||
}
|
||||
|
||||
public function scopeWarrantyExpired(Builder $query): Builder
|
||||
{
|
||||
return $query->whereNotNull('warranty_until')->whereDate('warranty_until', '<', now());
|
||||
}
|
||||
|
||||
public function scopeWarrantyExpiringSoon(Builder $query, int $days = 30): Builder
|
||||
{
|
||||
return $query
|
||||
->whereNotNull('warranty_until')
|
||||
->whereDate('warranty_until', '>=', now())
|
||||
->whereDate('warranty_until', '<=', now()->addDays($days));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user