Exemplo n.º 1
0
 function _test_should_return_false_when_destroy_fails()
 {
     $this->installAndIncludeModels('Post');
     $Post = new Post(array('title' => 'A Title'));
     $Post->save();
     $this->assertTrue($Post->destroy());
     $this->assertFalse($Post->destroy());
 }
Exemplo n.º 2
0
 public function destroy($id)
 {
     $post = Post::findOrFail($id);
     $this->authorOrAdminPermissioinRequire($post->user_id);
     Post::destroy($id);
     Flash::success(lang('Operation succeeded.'));
     return Redirect::route('posts.index');
 }
Exemplo n.º 3
0
 public static function _list()
 {
     $warning = "";
     if (isset($_POST['delete_post'])) {
         ///check if a user is logged in and if the logged in user is the one that wrote the blog post
         if (isset($_SESSION['user_id']) && $_SESSION['user_id'] == $_POST['user_id']) {
             Post::destroy($_POST['id']);
         } else {
             $warning = 'Sorry, you do not have permissions to delete that post';
         }
     }
     if (isset($_POST['update_post'])) {
         ///check if a user is logged in and if the logged in user is the one that wrote the blog post
         if (isset($_SESSION['user_id']) && $_SESSION['user_id'] == $_POST['user_id']) {
             Post::edit($_POST, $_POST['id']);
         } else {
             $warning = 'Sorry, you do not have permissions to edit that post';
         }
     }
     if (isset($_POST['create_post'])) {
         ///check if a user is logged in
         if (isset($_SESSION['user_id'])) {
             $_POST['user_id'] = $_SESSION['user_id'];
             Post::create($_POST);
         } else {
             $warning = 'Sorry, you must be logged in to submit a post';
         }
     }
     $posts_array = Post::getAll();
     if ($posts_array) {
         foreach ($posts_array as $post) {
             $blogger = Blogger::getOne($post['user_id']);
             $post['username'] = $blogger['username'];
         }
     }
     return array('posts' => $posts_array, 'warning' => $warning);
 }
Exemplo n.º 4
0
Arquivo: Post.php Projeto: fluzo/foro
 public function eliminar($id)
 {
     Post::destroy($id);
 }
Exemplo n.º 5
0
 /** @test **/
 public function it_destroys_the_model_with_the_given_id()
 {
     $this->createPostsTable();
     $this->insertOn('posts', ['title' => 'House', 'content' => 'Repeating']);
     $this->insertOn('posts', ['title' => 'Sherlock', 'content' => 'Elementary Watson.']);
     $this->insertOn('posts', ['title' => 'Psych!', 'content' => 'Repeating']);
     $this->assertEquals(3, Object::count());
     Post::destroy(2);
     $this->assertEquals(2, Object::count());
 }
Exemplo n.º 6
0
 public function delete_article($id)
 {
     $postInstance = Post::findOrFail($id);
     $postAuthor = $postInstance->user()->first();
     if (!Auth::user()->isAdmin() && Auth::user()->username != $postAuthor->username) {
         return Redirect::route('login');
     } else {
         // Also delete all comments:
         $commentsArray = $postInstance->comments()->get();
         foreach ($commentsArray as $oneComment) {
             Comment::destroy($oneComment->id);
         }
         Post::destroy($id);
         return Redirect::route("home");
     }
 }
Exemplo n.º 7
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int/array  $id
  * @return Response
  */
 public function destroy($id)
 {
     // delete base on id
     $post = Post::destroy(explode(',', $id));
     if ($post == 0) {
         // no resource deleted, return error object
         return $this->postService->notFound(explode(',', $id));
     }
     // otherwise return delete response
     return $this->postService->deletePostOkResponse();
 }
Exemplo n.º 8
0
 /**
  * Remove the specified post from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     Post::destroy($id);
     return Redirect::route('admin.posts.index')->with('message', 'Data berhasil dihapus');
 }
Exemplo n.º 9
0
 /**
  * Remove the specified post from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function delete($id)
 {
     Post::destroy($id);
     return Redirect::back();
 }
Exemplo n.º 10
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     Post::destroy($id);
     return Redirect::action('PostsController@index');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $post = Post::find($id);
     $this->deletePostImages($post);
     Post::destroy($id);
     return Redirect::to('admin/posts')->with(array('note' => 'Successfully Deleted Post', 'note_type' => 'success'));
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     //
     Post::destroy($id);
     //$post = findOrFail($id);
     return Redirect::route('posts.index');
 }
Exemplo n.º 13
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     if (Auth::check()) {
         $post = Post::find($id);
         $topic = $post->topic->id;
         Post::destroy($id);
         return Redirect::action('TopicController@show', array($topic))->with('message', 'Post deleted successfully');
     } else {
         return Redirect::to('login')->with('message', 'Please login to edit posts');
     }
 }
Exemplo n.º 14
0
 public function posts_delete()
 {
     $this->load->library('form_validation');
     if ($this->form_validation->run('delete-post') == FALSE) {
         redirect($this->session->previous_url, 'refresh');
     } else {
         $post = Post::find($this->input->post('id'));
         Post::destroy($this->input->post('id'));
         Comment::where('post_id', $post->id)->delete();
         $this->session->set_flashdata('message', 'Successfully deleted <strong>' . $post->title . '</strong>');
         redirect('dashboard/posts', 'refresh');
     }
 }
 /**
  * Remove the specified post from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     Post::destroy($id);
     return Redirect::route('admin.posts.index');
 }
Exemplo n.º 16
0
 /**
  * Remove the specified resource from storage.
  *
  */
 public function destroy($id)
 {
     // Delete all records on the Post-Tag and Post-Category pivot table
     Post::find($id)->tags()->detach();
     Post::find($id)->categories()->detach();
     Post::destroy($id);
     return Redirect::route('posts.index')->withInfo(Lang::get('larabase.post_deleted'));
 }