예제 #1
0
 /**
  * update post
  */
 public function update()
 {
     if (isset($_SESSION['login']) && $_SESSION['login'] === true) {
         $result = Post::edit();
         if ($result === true) {
             $this->redirectTo('posts/index');
         } else {
             if ($result === false) {
                 $this->messages[] = "The post dosn't updated, try again !";
                 $this->redirectTo('posts/edit/' . $this->idOfEditedPage);
             } else {
                 $this->messages = Post::$messages;
                 $this->idOfEditedPage = Post::$infos['id'];
                 $this->redirectTo('posts/edit/' . $this->idOfEditedPage);
                 return;
             }
         }
     } else {
         $this->redirectTo('posts/index');
     }
 }
예제 #2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     if (!$id) {
         return Redirect::back()->withErrors(array('Error! Can\'t update post.'))->withInput();
     }
     $formData = Input::all();
     $slug = new Slug();
     $formData['code'] = $slug->make($formData['name']);
     $rules = array('name' => 'required|min:6', 'preview_text' => 'required|max:300', 'text' => 'required');
     $validationResult = Validator::make($formData, $rules);
     if ($validationResult->fails()) {
         return Redirect::back()->withErrors($validationResult)->withInput();
     }
     $post = Post::getById($id);
     if ($post) {
         $post = Post::edit($post, $formData);
     }
     if (!$post) {
         return Redirect::back()->withErrors(array('Error! Can\'t update post.'))->withInput();
     }
     return Redirect::action('PostController@index');
 }