Passed
Push — master ( 49f1ef...b2146d )
by John
05:49 queued 11s
created

GroupSearchModel::search()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 11
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 18
rs 9.9
1
<?php
2
3
namespace App\Models\Search;
4
5
use Illuminate\Database\Eloquent\Model;
6
use DB;
7
8
class GroupSearchModel extends Model
9
{
10
    protected $table='group';
11
    protected $primaryKey='gid';
12
13
    public function search($key)
14
    {
15
        $result = [];
16
        //group name or gcode find
17
        if(strlen($key) >= 2){
18
            $ret = self::where(function($query) use ($key){
19
                $query->whereRaw('MATCH(`name`) AGAINST (? IN BOOLEAN MODE)',[$key])
20
                    ->orWhere('gcode', $key);
21
                })
22
                ->where('public',1)
23
                ->select('gid','gcode', 'img', 'name', 'description')
24
                ->get()->all();
25
            if(!empty($ret)){
26
                $result += $ret;
27
            }
28
        }
29
30
        return $result;
31
    }
32
}
33