/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = InstructorModel::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'name' => $this->name]); return $dataProvider; }
public function index() { $per_page = Input::get('per_page', 25); $search = Input::get('search', ''); $sede = Input::get('sede', 0); $order_by = Input::get('order', 'nombre_completo'); $order_dir = Input::get('orderdir', 'ASC'); $instructores = Instructor::with('user')->orderBy($order_by, $order_dir); if ($sede) { $instructores = $instructores->whereIn('user_id', function ($query) use($sede) { $query->select('id')->from('users')->where('sede_id', $sede); }); } if ($search != '') { $instructores = $instructores->where(function ($query) use($search) { $query->where('nombre_completo', 'like', '%' . $search . '%')->orwhere('cursos', 'like', '%' . $search . '%'); }); } $instructores = $instructores->paginate($per_page); return $this->response->paginator($instructores, new InstructorTransformer()); }
/** * Finds the Instructor model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Instructor the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Instructor::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }