<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class InstallRequestPhoto extends Model
{
    protected $appends = ['url'];

    protected $fillable = ['install_request_id', 'uploaded_by', 'path', 'type'];

    public function request(): BelongsTo
    {
        return $this->belongsTo(InstallRequest::class, 'install_request_id');
    }

    public function uploader(): BelongsTo
    {
        return $this->belongsTo(User::class, 'uploaded_by');
    }

    public function getUrlAttribute(): string
    {
        return asset('storage/' . $this->path);
    }

    public function installRequest(): BelongsTo
    {
        return $this->belongsTo(InstallRequest::class);
    }

}
