Exemplo n.º 1
0
 public static function updateGroups(Request $request)
 {
     $titles = $request::get('title');
     $ids = $request::get('id');
     $deleteId = $request::get('delete');
     $newtitle = $request::get('newtitle');
     $organizations = $request::get('organizations');
     $i = 0;
     if ($ids) {
         foreach ($ids as $id) {
             $group = District::find($id);
             $group->title = $titles[$i];
             if (!empty($organizations[$id])) {
                 $group->organization()->sync($organizations[$id]);
             }
             if (isset($deleteId[$i]) && $deleteId[$i] == $id) {
                 $group->delete();
             } else {
                 $group->save();
             }
             $i++;
         }
     }
     if ($newtitle) {
         $group = new District();
         $group->title = $newtitle;
         $group->save();
     }
     return true;
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     // validate request
     $validateDistrict = Validator::make($request->get('District'), District::$rules);
     $validationMessages = [];
     foreach ($request->get('DistrictTranslation') as $key => $value) {
         $validateDistrictTranslation = Validator::make($value, DistrictTranslation::$rules);
         if ($validateDistrictTranslation->fails()) {
             $validationMessages = array_merge_recursive($validationMessages, $validateDistrictTranslation->messages()->toArray());
         }
     }
     if ($validateDistrict->fails() or count($validationMessages) > 0) {
         $validationMessages = array_merge_recursive($validateDistrict->messages()->toArray(), $validationMessages);
         return redirect()->back()->withErrors($validationMessages)->withInput();
     }
     // get all languages
     $languages = Language::all();
     // find language default
     $languageDefault = $languages->where('is_key_language', 1)->first();
     if (is_null($languageDefault)) {
         $languageDefault = $languages->first();
     }
     // sure execute success, if not success rollback
     DB::transaction(function () use($request, $languageDefault) {
         $user = $request->user();
         // insert District
         $district = new District();
         $district->key = Common::createKeyURL($request->input('DistrictTranslation.' . $languageDefault->code . '.name'));
         $district->province_id = $request->input('District.province_id');
         $district->priority = $request->input('District.priority');
         $district->is_publish = $request->input('District.is_publish');
         $district->created_by = $user->name;
         $district->updated_by = $user->name;
         $district->save();
         // save data languages
         foreach ($request->get('DistrictTranslation') as $locale => $value) {
             $district->translateOrNew($locale)->name = $request->input('DistrictTranslation.' . $locale . '.name');
         }
         $district->save();
     });
     return redirect()->route('admin.districts.index');
 }
 public function store(DistrictRequest $request)
 {
     $district = new District();
     $district->name = $request['name'];
     $slug = preg_replace('/\\s+/', '-', $request['name']);
     $district->slug = $slug;
     $district->province = $request['provinceID'];
     $district->save();
     \Session::flash('success', $request['name'] . ' district has been successfully added!');
     return redirect()->back();
 }
Exemplo n.º 4
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $object = new Model();
     $params = $request->only('ru_title', 'en_title', 'ua_title', 'x', 'y');
     $filter = $object->validator($params);
     if ($filter->fails()) {
         $error = $filter->errors()->toArray();
         return view('admin.district.create', ['input' => $params, 'error' => $error]);
     }
     $object->fill($params);
     $object->save();
     return redirect('admin/district/' . $object->id);
 }
Exemplo n.º 5
0
 public function postDistricts(Request $request, $nationality_id, $state_id, $lga_id)
 {
     $rules = array('title' => 'required');
     $validator = Validator::make($request->all(), $rules);
     if ($validator->fails()) {
         return Redirect::to('/place/' . $nationality_id . '/' . $state_id . '/' . $lga_id)->withErrors($validator)->withInput($request->except('password'));
     } else {
         $user = new User();
         $user->id = 1;
         //$user = Auth::user();
         $record = new District();
         $record->title = $request->get('title');
         $record->lga()->associate(Lga::find($lga_id));
         $record->state()->associate(State::find($state_id));
         $record->nationality()->associate(Nationality::find($nationality_id));
         $record->user()->associate($user);
         $record->save();
         // redirect
         Session::flash('message', 'Successfully updated!');
         return Redirect::to('/place/' . $nationality_id . '/' . $state_id . '/' . $lga_id);
     }
 }