public function getDelete($sid)
 {
     // Find the announcement using the id
     $announcement = Announcement::find($sid);
     if ($announcement == null) {
         $errors = new \Illuminate\Support\MessageBag();
         $errors->add('deleteError', "The data cannot be deleted at this time.");
         return redirect('/admin/announcements')->withErrors($errors);
     }
     // Delete the announcement
     $announcement->delete();
     return redirect('admin/announcements');
 }
 public function postStore()
 {
     $sid = \Input::get('id');
     $validation = Announcement::validate(\Input::all());
     if ($validation->passes()) {
         $title = \Input::get('title');
         $content = \Input::get('content');
         $image = \Input::file('image');
         $private = \Input::get('private') == '' ? false : true;
         $announcement = isset($sid) ? Announcement::find($sid) : new Announcement();
         if ($announcement == null) {
             $errors = new \Illuminate\Support\MessageBag();
             $errors->add('editError', "The Announcement cannot be found because it does not exist or may have been deleted.");
             return redirect('/admin/announcements')->withErrors($errors);
         }
         $announcement->title = $title;
         $announcement->content = $content;
         $announcement->private = $private;
         $announcement->save();
         if (\Input::hasFile('image')) {
             //Upload the file
             $helper_image = new RImage();
             $filename = $helper_image->upload($image, 'announcements/' . $announcement->id, true);
             if ($filename) {
                 // create photo
                 $newimage = new Image();
                 $newimage->path = $filename;
                 // save photo to the loaded model
                 $announcement->images()->save($newimage);
             }
         }
         //if it validate
     } else {
         if (isset($sid)) {
             return redirect('admin/announcements/edit/' . $sid)->withErrors($validation)->withInput();
         } else {
             return redirect('admin/announcements/create')->withErrors($validation)->withInput();
         }
     }
     return redirect('admin/announcements');
 }
 public function testValidateFail()
 {
     $newAnnouncementInput = array('title' => 'open_.,<(Public)>!', 'content' => 'This is the body');
     $validation = Announcement::validate($newAnnouncementInput);
     $this->assertTrue(!$validation->passes());
 }