where() public static method

Add a basic where clause to the query.
public static where ( string $column, string $operator = null, mixed $value = null, string $boolean = 'and' )
$column string
$operator string
$value mixed
$boolean string
Beispiel #1
0
 /**
  * Perform column search
  *
  * @return void
  */
 public function doColumnSearch()
 {
     $input = $this->input;
     $columns = $input['columns'];
     // if older version, set the column name to query's fields
     // or if new version but does not use mData support
     if (!$this->new_version or !$this->mDataSupport and $this->new_version) {
         for ($i = 0; $i < count($columns); $i++) {
             if (!isset($this->columns[$i])) {
                 continue;
             }
             $columns[$i]['name'] = $this->columns[$i];
             if (stripos($columns[$i]['name'], ' AS ') !== false or $columns[$i]['name'] instanceof Expression) {
                 $columns[$i]['name'] = '';
                 $columns[$i]['searchable'] = false;
                 $columns[$i]['orderable'] = false;
             }
         }
     }
     for ($i = 0, $c = count($columns); $i < $c; $i++) {
         if ($columns[$i]['searchable'] == "true" and !empty($columns[$i]['search']['value']) and !empty($columns[$i]['name'])) {
             $column = $columns[$i]['name'];
             $keyword = $this->setupKeyword($columns[$i]['search']['value']);
             // wrap column possibly allow reserved words to be used as column
             $column = $this->wrapColumn($column);
             if ($this->isCaseInsensitive()) {
                 $this->query->whereRaw('LOWER(' . $column . ') LIKE ?', [strtolower($keyword)]);
             } else {
                 $col = strstr($column, '(') ? $this->connection->raw($column) : $column;
                 $this->query->where($col, 'LIKE', $keyword);
             }
         }
     }
 }
Beispiel #2
0
 protected function validateOwnership(Eloquent $model)
 {
     // Validate correct resource
     if ($model_id = Request::segment(2)) {
         $count = $model->where('id', $model_id)->where('user_id', Auth::id())->count();
         if ($count === 0) {
             return $this->respondNotFound();
         }
     }
 }
 /**
  * Perform column search
  *
  * @param  array $columns
  * @return void
  */
 public function doColumnSearch(array $columns)
 {
     for ($i = 0, $c = count($columns); $i < $c; $i++) {
         if ($columns[$i]['searchable'] == "true" and !empty($columns[$i]['search']['value']) and !empty($columns[$i]['name'])) {
             $column = $columns[$i]['name'];
             $keyword = $this->setupKeyword($columns[$i]['search']['value']);
             // wrap column possibly allow reserved words to be used as column
             $column = $this->wrapColumn($column);
             if ($this->isCaseInsensitive()) {
                 $this->query->whereRaw('LOWER(' . $column . ') LIKE ?', [strtolower($keyword)]);
             } else {
                 $col = strstr($column, '(') ? $this->connection->raw($column) : $column;
                 $this->query->where($col, 'LIKE', $keyword);
             }
         }
     }
 }
Beispiel #4
0
 /**
  * Фильтр: диапазон дат
  *
  * @param      $form_field
  * @param      $label
  * @param null $db_field
  */
 function addFilterRangeDate($form_field, $label, $db_field = null)
 {
     if (!$db_field) {
         $db_field = $form_field;
     }
     $gr = $this->form->putTbGroup($form_field)->setLabel($label);
     $gr->putTbDate('from')->setLabel('С')->setWrapClass('col-md-6')->setAppendClear();
     $gr->putTbDate('to')->setLabel('по')->setWrapClass('col-md-6')->setAppendClear();
     $from = \Input::get($form_field . '.from');
     $to = \Input::get($form_field . '.to');
     if ($from) {
         $this->model->where(function ($query) use($db_field, $from) {
             $query->where($db_field, '>=', \Carbon\Carbon::parse($from)->format('Y-m-d H:i:s'));
         });
     }
     if ($to) {
         $this->model->where(function ($query) use($db_field, $to) {
             $query->where($db_field, '<=', \Carbon\Carbon::parse($to)->format('Y-m-d H:i:s'));
         });
     }
 }
Beispiel #5
0
 /**
  * Delete a row with store_key
  *
  * @param $key
  * @return int
  */
 public static function storeDelete($key)
 {
     return parent::where(self::$storeColumn['key'], $key)->delete();
 }
 /**
  * @param string $slug
  * @return mixed
  */
 public function getBySlug($slug)
 {
     return $this->model->where('slug', $slug)->firstOrFail();
 }
 /**
  * Edit data by id
  * @param  mixed $value
  * @param  array $data
  * @param  string $field
  * @return int How many record has been changed
  */
 public function edit($value, array $data, $field = 'id')
 {
     $result = $this->model->where($field, $value)->update($data);
     return $result;
 }