<?php

namespace App\Models;

class Option extends BaseModel
{
    public static function get($table, $column, $key = null, $option_key = 'id')
    {
        if(!$key) {
            return self::where([
                ['table', '=', $table],
                ['column', '=', $column]
            ])->orderBy('sort')->get();
        }
        $option = self::where([
            ['table', '=', $table],
            ['column', '=', $column],
            ['key', '=', $key]
        ])->first();
        if(!$option) return '';
        return $option_key ? $option[$option_key] : $option;
    }

    public static function getById($id, $option_key = 'id')
    {
        $option = self::find($id);
        return $option ? $option[$option_key] : '';
    }
}
