<?php

namespace App\Models;

use App\Models\traits\SetConnection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Voice extends Model
{
    use SetConnection;
   // use SoftDeletes;

    protected $fillable = [
        'name',
        'store',
        'staff',
        'title',
        'text1',
        'text2',
        'text3',
        'text4',
        'text5',
        'text6',
        'text7',
        'text8',
        'text9',
        'text10',
        'text11',
        'text12',
        'text13',
        'text14',
        'text15',
        'photo',
        'kokai'
      ];

    public static function getData($params = []){
        $query = Voice::with(['relationStore', 'relationStaff']);
        if (isset($params['staff'])){
            $query->where('staff', $params['staff']);
        }
        if (isset($params['store_id'])){
            $query->where('store', $params['store_id']);
        }
        return $query->get();

    }
    public function relationStore(){
        return $this->hasOne(MstStore::class, 'code', 'store');
    }

    public function relationStaff(){
        return $this->hasOne(User::class, 'id', 'staff');
    }
}
