<?php

namespace App\Models;

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

class PortalHomesPanorama extends Model
{
    use SetConnection;

    protected  $table = 'portal_homes_panorama';
    const CREATED_AT = null;
    const UPDATED_AT = null;

    protected $fillable = [
        'id', 'company_id', 'article_id', 'file_path', 'reins_type', 'title', 'order', 'del', 'type', 'name', 'public_type'
    ];

    public function scopeOfImage(Builder $builder, $article_id, $type, $del = 0) {
        $res =  $builder->where('article_id', $article_id)
            ->where('type', $type)
            ->where('company_id', auth()->user()->company_id)
            ->where('del', $del);

        return $res;
    }

    public function scopeOfOrder(Builder $builder) {
        return $builder->orderBy('order');
    }

    public function scopeType(Builder $builder, $type) {
        return $builder->where('type', $type);
    }

    public function scopeDel(Builder $builder, $del) {
        return $builder->where('del', $del);
    }

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