コード例 #1
0
 /**
  * Store a subject in the Subject collection
  * 
  * @return View
  */
 public function addSubject()
 {
     $subject = new Subject();
     $subject->name = strtoupper(trim(Input::get('subject_name')));
     $subject->university_id = Auth::id();
     $subject->school = strtoupper(trim(Input::get('school')));
     $sections = explode(',', Input::get('section'));
     foreach ($sections as $section) {
         $sect = new Section();
         $sect->code = strtoupper(trim($section));
         $sect->is_free = true;
         $subject->sections()->associate($sect);
     }
     try {
         $subject->save();
     } catch (MongoDuplicateKeyException $e) {
         return Redirect::back()->withErrors(array('error' => Lang::get('add_subject.subject_duplicated')));
     }
     return Redirect::to(Lang::get('routes.add_subject'))->with('message', Lang::get('add_subject.success'));
 }