/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = PostCategory::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->joinWith(['post', 'category']); /*$query->andFilterWhere([ 'post_id' => $this->post_id, 'category_id' => $this->category_id, ]);*/ $query->andFilterWhere(['like', 'post_title', $this->post_id])->andFilterWhere(['like', 'category_name', $this->category_id]); return $dataProvider; }
public function actionList() { $dataProvider = new ActiveDataProvider(['query' => PostCategory::find()]); return $this->render('list', ['dataProvider' => $dataProvider]); }
/** * move resources * * @param int $id * * @return Response */ public function move($id) { $validator = Validator::make(Input::all(), ['parent_id' => 'exists:post_category,id']); if ($validator->fails()) { throw new ResourceException($validator->errors()->first()); } if (is_null($category = PostCategory::find($id))) { return $this->postCategoryPresenter->errorNotFound(); } if (Input::has('parent_id')) { $dest = PostCategory::find(Input::get('parent_id')); } else { $dest = PostCategory::root(); } if (!is_null($next = Input::get('next_id'))) { $next = PostCategory::find(Input::get('next_id')); } if (!is_null($prev = Input::get('prev_id'))) { $prev = PostCategory::find(Input::get('prev_id')); } // dest = null, move to parent // dest = null, next = null, move to parent and last if (is_null($dest) && is_null($next) && !is_null($prev)) { //move to parent and last $category->moveToRightOf($prev); } else { if (is_null($dest) && !is_null($next)) { //move to parent $category->moveToLeftOf($next); } else { if (!is_null($dest) && is_null($next)) { $category->makeLastChildOf($dest); } else { //move to parent $category->moveToLeftOf($next); } } } return response()->return(); }