Example #1
0
 /**
  * @param \Illuminate\Database\Eloquent\Builder|static $query
  * @param string $keyword
  * @param boolean $matchAllFields
  */
 public static function scopeSearch($query, $keyword, $matchAllFields = false)
 {
     return static::where(function ($query) use($keyword, $matchAllFields) {
         foreach (static::getSearchFields() as $field) {
             if ($matchAllFields) {
                 $query->where($field, 'LIKE', "%{$keyword}%");
             } else {
                 $query->orWhere($field, 'LIKE', "%{$keyword}%");
             }
         }
     });
 }
Example #2
0
 public static function reset($sql = '')
 {
     // 保存最后的数据库操作语句
     if ($sql) {
         static::$lastSql = $sql;
     }
     static::$pdo = '';
     static::$pk = array('key' => 'id', 'value' => '');
     static::$table = '';
     // 默认是 AR 的调用模式, 获取当前 AR 类名,即为表名
     static::$where = '';
     static::$orWhere = '';
     static::$sqlSelect = array('fields' => '', 'group' => '', 'order' => '', 'limit' => '');
     static::$saveData = [];
     static::$bindValue = [];
 }