Passed
Push — master ( b3147e...c49c81 )
by Ferry
03:13
created

SelectController::postLookup()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 19
rs 9.5222
c 0
b 0
f 0
cc 5
nc 3
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: User
5
 * Date: 5/10/2019
6
 * Time: 10:38 PM
7
 */
8
9
namespace crocodicstudio\crudbooster\types\select;
10
11
use Illuminate\Routing\Controller as BaseController;
12
use Illuminate\Support\Facades\DB;
13
14
class SelectController extends BaseController
15
{
16
    public function postLookup() {
17
        $foreignKey = decrypt(request('foreign_key'));
0 ignored issues
show
Bug introduced by
It seems like request('foreign_key') can also be of type array; however, parameter $value of decrypt() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

17
        $foreignKey = decrypt(/** @scrutinizer ignore-type */ request('foreign_key'));
Loading history...
18
        $foreignValue = request('foreign_value');
19
        $table = decrypt(request('table'));
20
        $sqlCondition = decrypt(request('sql_condition'));
21
        if($foreignKey && $foreignValue && $table) {
22
23
            $data = DB::table($table)
24
                ->where($foreignKey, $foreignValue);
25
            if($sqlCondition) {
26
                $data->whereRaw($sqlCondition);
27
            }
28
29
            $data = $data->get();
30
31
            return response()->json(['status'=>true, 'data'=>$data]);
32
33
        }else{
34
            return response()->json(['status'=>false]);
35
        }
36
    }
37
}