public function lga()
 {
     $query = \Input::get('z');
     $list = \App\Lga::where('state_id', '=', $query)->lists('name', 'id')->all();
     if (count($list) > 0) {
         foreach ($list as $key => $value) {
             $data[] = array('id' => $key, 'text' => $value);
         }
     } else {
         $data[] = array('id' => '0', 'text' => 'No areas/region found');
     }
     return \Response::json(['data' => $data]);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     $filename = base_path('public/nigeria.json');
     $data = json_decode(file_get_contents($filename), TRUE);
     foreach ($data as $key => $value) {
         $state = State::create(array('state' => $key, 'capital' => $value['capital'], 'population' => $value['population'], 'area' => $value['land_area'], 'nickname' => $value['nick_name'], 'date_created' => $value['date_created'], 'preceding_entity' => $value['preceding_entity'], 'lg_count' => $value['lg_count']));
         for ($i = 1; $i < count($value['lga']); $i++) {
             $lga = Lga::create(array('state_id' => $state->id, 'lg_name' => $value['lga'][$i]));
         }
     }
     // $this->call('UserTableSeeder');
     Model::reguard();
 }
Beispiel #3
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);
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(LocationUpdateRequest $request, $id)
 {
     $state = State::findOrFail($id);
     $state->name = $request->input('state');
     $state->save();
     $lgas = $request->input('lga');
     $real = [];
     $state->lgas()->delete();
     foreach ($lgas as $lga) {
         if ($existingArea = Lga::where('name', $lga)->first()) {
             $real[] = $existingArea;
         } else {
             $newArea = new Lga();
             $newArea->name = $lga;
             $newArea->save();
             $real[] = $newArea;
         }
     }
     $state->lgas()->saveMany($real);
     return redirect("/admin/location/")->withSuccess("Changes saved.");
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $biz = Biz::findorFail($id);
     $cat = $biz->cats->lists('id')->all();
     $sub = $biz->subcats->lists('id')->all();
     // dd($sub);
     $catList = Cat::lists('name', 'id');
     $subList = SubCat::lists('name', 'id');
     // dd($subList);
     $stateList = State::lists('name', 'id');
     $lgaList = Lga::lists('name', 'id');
     //$area= Address::lists
     //dd($biz->address->state->name);
     //  foreach ($biz->subcats as $sub) {
     //      $currentSubs[] = $sub->id;
     //  }
     //   if(empty($currentSubs)){
     //      $currentSubs = '';
     //  }
     return view('admin/biz/edit', compact('biz', 'catList', 'subList', 'stateList', 'cat', 'currentSubs', 'lgaList', 'sub'));
 }
 public function profile($userId)
 {
     $cats = Cat::all();
     $user = \App\User::findOrFail($userId);
     $bizs = $user->favours;
     $favourites = \DB::table('favourites')->whereUserId(\Auth::user()->id)->lists('biz_id');
     //$bizs = Biz::orderBy('created_at', 'desc')->paginate(6);
     $stateList = State::lists('name', 'name');
     $lgaList = Lga::lists('name', 'id');
     $catList = Cat::lists('name', 'name');
     $featured = Biz::whereFeatured('YES')->paginate(3);
     $recent = Biz::orderBy('created_at', 'desc')->paginate(2);
     // dd($featured);
     return view('pages.user-profile', compact('stateList', 'lgaList', 'catList', 'cats', 'bizs', 'user', 'favourites', 'featured', 'recent', 'totalBiz', 'totalCat'));
 }