<?php

namespace App\Models;

use App\Models\traits\SetConnection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Database\Eloquent\Model;

class PortalSuumoPhoto extends Model
{
    use SetConnection;

    protected $fillable = [
        'article_id', 'file_type', 'file_path', 'memo', 'order', 'company_id', 'type', 'created_at', 'del', 'facility_name', 'property'
    ];

    const CREATED_AT = null;
    const UPDATED_AT = null;

    //

    public static function getImgByArticleId($type, $id)
    {
        $res = PortalSuumoPhoto::where('article_id', '=', $id)->where('type', $type)->where("company_id", auth()->user()->company_id)
            ->orderBy('order')
            ->get();
        return $res;
    }

    public function getStorageLinkAttribute()
    {
        return str_replace('public', '/storage', $this->attributes["file_path"]);
    }
}
