public function post_create() { $new_category = array('title' => trim(Input::get('title')), 'slug' => trim(Input::get('slug')), 'image' => trim(Input::get('image')), 'visibility' => trim(Input::get('visible')) ? true : false); //set up rules for new data $rules = array('title' => 'required|min:3|max:128', 'slug' => 'unique:categories,slug'); // make the validator $v = Validator::make($new_category, $rules); if ($v->fails()) { // redirect to form // errors return Redirect::to('user/categories/create')->with_errors($v)->with_input(); } // create the new category $category = new Category($new_category); $category->save(); // add organisations to Organisation_Category foreach (Input::get('organisations') as $org_id) { $category->organisations()->attach($org_id); } // redirect to posts return Redirect::to('user/categories')->with('success', 'A new category has been created'); }