Files
sam-manage/app/Models/Juil/ConstructionSitePhoto.php

66 lines
1.5 KiB
PHP
Raw Normal View History

<?php
namespace App\Models\Juil;
use App\Models\User;
use App\Traits\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
class ConstructionSitePhoto extends Model
{
use BelongsToTenant, SoftDeletes;
protected $table = 'construction_site_photos';
protected $fillable = [
'tenant_id',
'user_id',
'site_name',
'work_date',
'description',
'before_photo_path',
'before_photo_gcs_uri',
'before_photo_size',
'during_photo_path',
'during_photo_gcs_uri',
'during_photo_size',
'after_photo_path',
'after_photo_gcs_uri',
'after_photo_size',
];
protected $casts = [
'work_date' => 'date',
'before_photo_size' => 'integer',
'during_photo_size' => 'integer',
'after_photo_size' => 'integer',
'created_at' => 'datetime',
'updated_at' => 'datetime',
'deleted_at' => 'datetime',
];
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function hasPhoto(string $type): bool
{
return !empty($this->{$type . '_photo_path'});
}
public function getPhotoCount(): int
{
$count = 0;
foreach (['before', 'during', 'after'] as $type) {
if ($this->hasPhoto($type)) {
$count++;
}
}
return $count;
}
}