コード例 #1
0
ファイル: GroupRepository.php プロジェクト: TorchSK/woofyard
 public function search($filters, $sortBy, $sortOrder, $paginate = 1)
 {
     if ($paginate == NULL) {
         $paginate = true;
     }
     $table = 'groups';
     $result = $this->model->leftjoin('group_user', 'group_user.group_id', '=', $table . '.id')->where(function ($query) use($filters, $sortBy, $sortOrder) {
         foreach ((array) $filters as $key => $temp) {
             if ($filters[$key]) {
                 if ($key == 'name') {
                     $query->whereRaw("name like '%" . $filters[$key]['item0'] . "%'");
                 } else {
                     $query->whereIn($key, array($filters[$key]));
                 }
             }
         }
     })->orderBy($sortBy, $sortOrder)->groupBy($table . '.id');
     if ($paginate) {
         return $result->paginate(10, [$this->model->getTable() . '.*', DB::raw('count(group_user.group_id) as members_count')]);
     } else {
         return $result->get([$this->model->getTable() . '.*', DB::raw('count(group_user.group_id) as members_count')]);
     }
 }
コード例 #2
0
 /**
  * Get the path to the compiled version of a view.
  *
  * @param  Illuminate\Database\Eloquent\Model  $model
  * @return string
  */
 public function getCompiledPath($model)
 {
     /*
      * A unique path for the given model instance must be generated
      * so the view has a place to cache. The following generates a
      * path using almost the same logic as Blueprint::createIndexName()
      *
      * e.g db_table_name_id_4
      */
     $field = $this->config->get('db-blade-compiler.model_property');
     $path = 'db_' . $model->getTable() . '_' . $model->{$field} . '_';
     if (is_null($model->primaryKey)) {
         $path .= $model->id;
     } else {
         if (is_array($model->primaryKey)) {
             $path .= implode('_', $model->primaryKey);
         } else {
             $path .= $model->primaryKey;
         }
     }
     $path = strtolower(str_replace(array('-', '.'), '_', $path));
     return $this->cachePath . '/' . md5($path);
 }