public function post_create() { $new_faq = array('question' => trim(Input::get('question')), 'answer' => trim(Input::get('answer')), 'sort_order' => trim(Input::get('sort_order'))); //set up rules for new data $rules = array('question' => 'required|min:3', 'answer' => 'required', 'sort_order' => 'numeric'); // make the validator $v = Validator::make($new_faq, $rules); if ($v->fails()) { // redirect to form // errors return Redirect::to('user/faqs/create')->with_errors($v)->with_input(); } // create the new faq $faq = new Faq($new_faq); $faq->save(); // add categories to Faqcategory_Faq foreach (Input::get('faqcategories') as $faqcategory_id) { $faq->faqcategories()->attach($faqcategory_id); } // add organisations to Organisation_Faq foreach (Input::get('organisations') as $org_id) { $faq->organisations()->attach($org_id); } // redirect to faqs return Redirect::to('user/faqs')->with('success', 'A new faq has been created'); }