Example #1
0
 /**
  * Show the form for creating a new resource.
  *
  * @return Response
  */
 public function create()
 {
     $this->model->title = $_POST['post']['title'];
     $this->model->info = $_POST['post']['info'];
     $this->model->link = $_POST['post']['link'];
     $this->model->user_id = \Auth::user()->id;
     $matches = null;
     preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\\/)[^&\n]+(?=\\?)|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $_POST['post']['link'], $matches);
     if ($matches != null) {
         $this->model->type_id = 1;
         $this->model->link = $matches[0];
     } else {
         $this->model->type_id = 2;
     }
     $this->model->save();
     if (isset($_POST['categories'])) {
         foreach ($_POST['categories'] as $categorie) {
             $post_categories = new \App\post_categories();
             $post_categories->post_id = $this->model->id;
             $post_categories->categorie_id = $categorie;
             $post_categories->save();
         }
     }
     header('Location:' . url());
     exit;
 }
 /**
  * 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;
 }