'datetime', 'kilometer' => 'decimal:2', 'pressure_high' => 'decimal:2', 'pressure_low' => 'decimal:2', 'cabin_temperature' => 'decimal:2', 'front_image_metadata' => 'array', 'cabin_temperature_image_metadata' => 'array', 'ac_image_metadata' => 'array', 'blower_image_metadata' => 'array', 'evaporator_image_metadata' => 'array', ]; /** * Get the transaction associated with the Postcheck * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function transaction() { return $this->belongsTo(Transaction::class); } /** * Get the user who performed the postcheck * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function postcheckBy() { return $this->belongsTo(User::class, 'postcheck_by'); } /** * Get front image URL */ public function getFrontImageUrlAttribute() { return $this->front_image ? Storage::disk('public')->url($this->front_image) : null; } /** * Get cabin temperature image URL */ public function getCabinTemperatureImageUrlAttribute() { return $this->cabin_temperature_image ? Storage::disk('public')->url($this->cabin_temperature_image) : null; } /** * Get AC image URL */ public function getAcImageUrlAttribute() { return $this->ac_image ? Storage::disk('public')->url($this->ac_image) : null; } /** * Get blower image URL */ public function getBlowerImageUrlAttribute() { return $this->blower_image ? Storage::disk('public')->url($this->blower_image) : null; } /** * Get evaporator image URL */ public function getEvaporatorImageUrlAttribute() { return $this->evaporator_image ? Storage::disk('public')->url($this->evaporator_image) : null; } /** * Delete associated files when model is deleted */ protected static function boot() { parent::boot(); static::deleting(function ($postcheck) { $imageFields = [ 'front_image', 'cabin_temperature_image', 'ac_image', 'blower_image', 'evaporator_image' ]; foreach ($imageFields as $field) { if ($postcheck->$field && Storage::disk('public')->exists($postcheck->$field)) { Storage::disk('public')->delete($postcheck->$field); } } }); } /** * Get the AC condition options * * @return array */ public static function getAcConditionOptions() { return ['sudah dikerjakan', 'sudah diganti']; } /** * Get the blower condition options * * @return array */ public static function getBlowerConditionOptions() { return ['sudah dibersihkan atau dicuci', 'sudah diganti']; } /** * Get the evaporator condition options * * @return array */ public static function getEvaporatorConditionOptions() { return ['sudah dikerjakan', 'sudah diganti']; } /** * Get the compressor condition options * * @return array */ public static function getCompressorConditionOptions() { return ['sudah dikerjakan', 'sudah diganti']; } /** * Scope to filter by transaction * * @param \Illuminate\Database\Eloquent\Builder $query * @param int $transactionId * @return \Illuminate\Database\Eloquent\Builder */ public function scopeByTransaction($query, $transactionId) { return $query->where('transaction_id', $transactionId); } /** * Scope to filter by user who performed postcheck * * @param \Illuminate\Database\Eloquent\Builder $query * @param int $userId * @return \Illuminate\Database\Eloquent\Builder */ public function scopeByUser($query, $userId) { return $query->where('postcheck_by', $userId); } /** * Scope to filter by date range * * @param \Illuminate\Database\Eloquent\Builder $query * @param string $startDate * @param string $endDate * @return \Illuminate\Database\Eloquent\Builder */ public function scopeByDateRange($query, $startDate, $endDate) { return $query->whereBetween('postcheck_at', [$startDate, $endDate]); } }