Total Complexity | 5 |
Total Lines | 40 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
17 | class SelectQuery |
||
18 | { |
||
19 | use DefaultOption, Join; |
||
20 | |||
21 | /** |
||
22 | * @param callable|string $query DB Query Builder|SQL RAW |
||
23 | * @return $this |
||
24 | */ |
||
25 | public function optionsFromQuery($query) { |
||
26 | $data = columnSingleton()->getColumn($this->index); |
||
27 | /** @var $data SelectQueryModel */ |
||
28 | $data->setOptionsFromQuery($query); |
||
29 | |||
30 | columnSingleton()->setColumn($this->index, $data); |
||
31 | |||
32 | if(is_callable($query)) { |
||
33 | $result = call_user_func($query); |
||
34 | }else{ |
||
35 | $result = DB::select(DB::raw($query)); |
||
36 | } |
||
37 | |||
38 | if($result) { |
||
39 | $options = []; |
||
40 | foreach($result as $r) { |
||
41 | $options[ $r->key ] = $r->label; |
||
42 | } |
||
43 | $this->options($options); |
||
44 | } |
||
45 | |||
46 | return $this; |
||
47 | } |
||
48 | |||
49 | private function options($data_options) { |
||
57 | } |
||
58 | } |