Beispiel #1
0
 public static function remove($id)
 {
     if (empty($id)) {
         return false;
     }
     try {
         $post = Post::getById($id);
         if ($post->user->id == Auth::user()->id) {
             return $post->delete();
         } else {
             false;
         }
     } catch (Exception $e) {
         Log::info('Post:remove(): ' . $e->getMessage());
         return array();
     }
 }
 /**
  * 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');
 }