protected function processForm($mode, $category_id, $id = null) { $input = array_filter(Input::all()); $rules = ['category_id' => 'required', 'title' => 'required|unique:categories', 'user_id' => 'required']; if ($this->user_id == Input::get('user_id')) { if ($id) { $subcategory = Subcategories::find($id); $messages = $this->validateCategory($input, $rules); if ($messages->isEmpty()) { $subcategory = $subcategory->update($input); } } else { $messages = $this->validateCategory($input, $rules); if ($messages->isEmpty()) { $subcategory = $this->create($input); $subcategory = Subcategory::create($input); } } if ($messages->isEmpty()) { return Redirect()->to('user/download/subcategories')->withSuccess(trans('validation.success')); } return Redirect()->back()->withInput()->withErrors($messages); } else { return Redirect()->back()->withInput()->withErrors(trans('validation.userid-problem')); } }
/** * Run the database seeds. * * @return void */ public function run() { Subcategory::create(['category_id' => 1, 'name' => 'First type']); Subcategory::create(['category_id' => 2, 'name' => 'Second type']); Subcategory::create(['category_id' => 1, 'name' => 'Third type']); }