public function store() { $rules = ['crop_name' => 'required', 'category_id' => 'required']; $data = Input::all(); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator); } else { $crop = new Crop(); $crop->crop_name = $data['crop_name']; $crop->category_id = $data['category_id']; if ($crop->save()) { return Redirect::route('crops.index')->with('success', 'Successfully Created!'); } else { return Redirect::route('crops.index')->with('error', 'Something Went Wrong. Try Again.'); } } }