public function buildQuery($query = null) { if ($query == null) { $query = Recipe::query(); } if (Input::has('query')) { $term = Input::get('query'); $query->where(function ($q) use($term) { $q->where('recipes.description', 'like', "%{$term}%")->orWhere('recipes.presentation', 'like', "%{$term}%"); }); $this->params['query'] = $term; } if (Input::has('title')) { $title = Input::get('title'); $query->where('recipes.title', 'like', "%{$title}%"); $this->params['title'] = $title; } if (Input::has('category')) { $category = Input::get('category'); if ($category != '*') { $query->where('category', '=', $category); $this->params['category'] = $category; } } if ($this->cookbook != '*') { $query->where('cookbook', '=', $this->cookbook); $this->params['cookbook'] = $this->cookbook; } elseif (Input::has('cookbook') && Input::get('cookbook') != '*') { $cookbook = Input::get('cookbook'); $query->where('cookbook', '=', $cookbook); $this->params['cookbook'] = $cookbook; } return $query; }
public function search($input) { $query = Recipe::query(); $columns = Schema::getColumnListing('recipes'); $attributes = array(); foreach ($columns as $attribute) { if (isset($input[$attribute]) and !empty($input[$attribute])) { $query->where($attribute, $input[$attribute]); $attributes[$attribute] = $input[$attribute]; } else { $attributes[$attribute] = null; } } return [$query->get(), $attributes]; }