<?php
/**
 * Created by PhpStorm.
 * User: vlaps
 * Date: 26.11.2018
 * Time: 10:58
 */

namespace App\Repositories;

abstract class Reposytory
{
    protected $model = FALSE;
    public function get($select = '*', $take = FALSE, $where = FALSE, $whereIn = FALSE)
    {
        if (session()->has('lang') AND session()->get('lang') == 'ua') {
            $builder = $this->model->setConnection('mysqlUA')->select($select);
        } else {
            $builder = $this->model->select($select);
        }
        if ($take) {
            $builder->take($take);
        }
        if ($where) {
            $builder->where($where[0], $where[1], $where[2]);
        }
        if ($whereIn) {
            $builder->whereIn('id', $whereIn);
        }
        return $this->check($builder->get());
    }
    protected function check($result)
    {
        if ($result->isEmpty()) {
            return FALSE;
        }
        return $result;
    }
}
