/**
  * Update the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $post = \App\Posts::find($id);
     $post->title = $_POST['post']['title'];
     $post->link = $_POST['post']['link'];
     $post->post = $_POST['post']['post'];
     $post->info = $_POST['post']['info'];
     $post->save();
     if (isset($_POST['categories'])) {
         \App\post_categories::where('post_id', '=', $id)->delete();
         foreach ($_POST['categories'] as $cat) {
             $model = new \App\post_categories();
             $model->post_id = $id;
             $model->categorie_id = $cat;
             $model->save();
         }
     }
     // Send a message to user
     $reason = $_POST['reason'];
     if (isset($_POST['other_reason']) && $_POST['other_reason'] != "") {
         $reason = $_POST['other_reason'];
     } else {
         $reason = $_POST['reason'];
     }
     $message = "Your post has been edited due to the following reason: " . $reason;
     \App\Message::send($post->user()->id, 2, "Your post has been edited", $message);
     header('Location:' . url('admin/posts/edit/' . $id));
     exit;
 }
예제 #2
0
 public static function getPostByCategory($category_id)
 {
     $post_ids = \App\post_categories::where('categorie_id', '=', $category_id)->get();
     $posts = new \App\Posts();
     $ids = array();
     foreach ($post_ids as $id) {
         $ids[] = $id->post_id;
     }
     $posts = \App\Posts::whereIn('id', $ids);
     return $posts->get();
 }