/
home
/
old_henza
/
server
/
app
/
Te
/
File Upload :
llllll
Current File: /home/old_henza/server/app/Te/Search.php
<?php namespace App\DB\Te; /** * Created by PhpStorm. * User: AraNote * Date: 12/04/2018 * Time: 10:32 PM */ class Search { protected $cols, $text, $query; public static function query(&$query, $cols, $search) { $query->where(function ($q) use ($cols, $search) { $first = true; foreach ($cols as $col) { if (self::hasJoin($col)) { $exp = explode('.', $col); if (sizeof($exp) > 2) { $q->{($first) ? 'whereHas' : 'orWhereHas'} ($exp[0], function ($q) use ($exp, $search) { return $q->whereHas($exp[1], function ($q2) use ($exp, $search) { return $q2->where($exp[2], 'LIKE', '%' . $search . '%'); }); }); } else { $q->{($first) ? 'whereHas' : 'orWhereHas'} ($exp[0], function ($q) use ($exp, $search) { return $q->where($exp[1], 'LIKE', '%' . $search . '%'); }); } } else { $q->{($first) ? 'where' : 'orWhere'}($col, 'LIKE', '%' . $search . '%'); } if ($first) { $first = false; } } }); } public static function hasJoin($col) { return sizeof(explode('.', $col)) > 1; } }
Copyright ©2k19 -
Hexid
|
Tex7ure