모델, 서비스, 컨트롤러, React SPA 뷰, 라우트 추가 GCS 업로드/다운로드, 드래그앤드롭 사진 관리 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
66 lines
1.5 KiB
PHP
66 lines
1.5 KiB
PHP
<?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;
|
|
}
|
|
}
|