Conditions | 7 |
Paths | 12 |
Total Lines | 19 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
36 | public function optionsFromTable($table, $key_field, $display_field, $SQLCondition = null) { |
||
37 | |||
38 | if(strpos($table,"App\Models")!==false) { |
||
39 | $table = new $table(); |
||
40 | $table = $table::$tableName; |
||
41 | } |
||
42 | |||
43 | $data = DB::table($table); |
||
|
|||
44 | if($SQLCondition && is_callable($SQLCondition)) { |
||
45 | $data = call_user_func($SQLCondition, $data); |
||
46 | }elseif ($SQLCondition && is_string($SQLCondition)) { |
||
47 | $data->whereRaw($SQLCondition); |
||
48 | } |
||
49 | $data = $data->get(); |
||
50 | $options = []; |
||
51 | foreach ($data as $d) { |
||
52 | $options[ $d->$key_field ] = $d->$display_field; |
||
53 | } |
||
54 | $this->options($options); |
||
55 | } |
||
56 | } |