/**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     BlogCategory::where('parent_id', '=', $id)->delete();
     $cat = BlogCategory::find($id);
     if ($cat) {
         $cat->delete();
     }
     return array('status' => 'OK');
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $input = array_except(Input::all(), array('_method', '_token', 'categories', 'file', 'categories_ids'));
     if (empty($input['name'])) {
         $input['name'] = str_slug($input['title'], '-');
     }
     $post = $this->post->find($id);
     $rules = Post::$rules;
     if ($post->id) {
         $rules['name'] = $rules['name'] . ', ' . $post->id;
     }
     $validation = Validator::make($input, $rules);
     if ($validation->passes()) {
         $input['active'] = isset($input['active']) ? (int) $input['active'] : 0;
         if (!$input['publishied_at']) {
             $input['publishied_at'] = date("Y-m-d H:i:s");
         }
         $input['user_id'] = Auth::user()->id;
         $post->update($input);
         $categories = array();
         foreach (explode(',', Input::get('categories_ids')) as $cat_id) {
             if ($cat = \BlogCategory::where('id', '=', $cat_id)->first()) {
                 $categories[] = $cat->id;
             }
         }
         $post->categories()->sync($categories);
         return Redirect::route('posts.index');
     }
     return Redirect::route('posts.edit', $id)->withInput()->withErrors($validation)->with('message', trans('validation.errors'));
 }