Esempio n. 1
0
 /**
  * Eloquent scope of the search
  * 
  * @param  \App\LaravelRestCms\BaseModel $query
  * @param  string $keyword
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeSearch(\App\LaravelRestCms\BaseModel $query, $keyword = null)
 {
     $searchCols = $this->getSearchCols(null, static::$labelCol);
     $query->select('*', implode(' ', static::$labelCol) . ' as label', 'url');
     $match = '';
     // make search results use the "and" clause
     $keyword[0] = '"' . $keyword[0] . '"';
     if (is_array($searchCols)) {
         foreach ($searchCols as $searchCol) {
             $match = "MATCH(" . $searchCol . ") AGAINST (? IN BOOLEAN MODE)";
             $query = $query->whereRaw($match, $keyword);
         }
     }
     return $query->orderByRaw($match . ' desc', $keyword);
 }
 /**
  * Transforms a  model
  * Be default, it exposes all attributes
  * Overide this to hide attributes
  * 
  * @param  \App\LaravelRestCms\BaseModel $model
  * @return array
  */
 public function transform(BaseModel $model)
 {
     return $model->getAttributes();
 }