'date', 'warranty_expiry_date' => 'date', 'purchase_cost' => 'decimal:2', ]; /** * Get the asset type of this asset. */ public function assetType() { return $this->belongsTo(AssetType::class); } /** * Get the user who created this asset. */ public function creator() { return $this->belongsTo(User::class, 'created_by'); } /** * Get the assignments for this asset. */ public function assignments() { return $this->hasMany(AssetAssignment::class); } /** * Get the current assignment for this asset. */ public function currentAssignment() { return $this->hasOne(AssetAssignment::class)->whereNull('checkin_date')->latest(); } /** * Get the maintenances for this asset. */ public function maintenances() { return $this->hasMany(AssetMaintenance::class); } /** * Get the depreciation for this asset. */ public function depreciation() { return $this->hasOne(AssetDepreciation::class); } /** * Scope a query to only include available assets. */ public function scopeAvailable($query) { return $query->where('status', 'available'); } /** * Scope a query to only include assigned assets. */ public function scopeAssigned($query) { return $query->where('status', 'assigned'); } /** * Scope a query to only include assets under maintenance. */ public function scopeUnderMaintenance($query) { return $query->where('status', 'under_maintenance'); } /** * Scope a query to only include disposed assets. */ public function scopeDisposed($query) { return $query->where('status', 'disposed'); } }