Example #1
0
 /**
  * Function that it will handle with post creation and validate all fields of creation
  * @todo Fix upload bug , since when we dont specify a cover it will try upload something
  */
 public function post_new()
 {
     $new_post = Input::all();
     unset($new_post['csrf_token']);
     unset($new_post['tags']);
     unset($new_post['_continue']);
     unset($new_post['_cancel']);
     $new_post['slug'] = Str::slug($new_post['title']);
     $rules = array('cover' => 'image', 'title' => 'required|min:3|max:255|unique:projects', 'slug' => 'required');
     $validation = Validator::make($new_post, $rules);
     if ($validation->fails()) {
         return Redirect::to('dojo/projects')->with('user', Auth::user())->with_errors($validation)->with_input();
     }
     # cover upload handler
     if (!empty($new_post['cover']['name'])) {
         $extension = File::extension($new_post['cover']['name']);
         $directory = path('public') . 'images/thumbnails/projects/';
         $filename = sha1(time()) . ".{$extension}";
         $upload_sucess = Input::upload('cover', $directory, $filename);
         if ($upload_sucess) {
             $new_post['cover'] = URL::to('images/thumbnails/projects/' . $filename);
         }
     } else {
         unset($new_post['cover']);
     }
     $new_project = new Project($new_post);
     $new_project->save();
     return Redirect::to('dojo/projects/');
 }
Example #2
0
 public static function post_delete($id)
 {
     $project = Project::with('author')->find($id);
     $project->delete();
 }