/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('barrios')->delete();
     for ($i = 0; $i < 10; $i++) {
         Barrio::create(['postal_code' => 12345 + $i, 'url_name' => 'barrio-' . $i, 'name' => 'barrio ' . $i]);
     }
 }
 public function getIndex($url_name)
 {
     $barrio = Barrio::where('url_name', '=', $url_name)->first();
     if (!$barrio) {
         return view('errors.404');
     }
     return view('frontend.news.index', ['barrio' => $barrio]);
 }
 public function postSearchBarrio(RequestHttp $request)
 {
     $this->validate($request, ['postal_code' => 'required|max:5|min:5']);
     $barrio = Barrio::where('postal_code', '=', Request::input('postal_code'))->first();
     if (!$barrio) {
         Session::forget('barrio_search');
         return redirect('not-found');
     }
     Session::put('barrio_search', $barrio);
     return redirect($barrio['url_name']);
 }
 public function getIndex($url_name)
 {
     $barrio = Barrio::where('url_name', '=', $url_name)->first();
     if (!$barrio) {
         return view('errors.404');
     }
     $data = [];
     $data['barrio'] = $barrio;
     $data['general'] = 1;
     $data['dashboardAuth'] = 1;
     return view('frontend.forums.index', $data);
 }
 /**
  * Function to get view profile
  * @return view
  */
 public function getProfile()
 {
     $barrio = Barrio::where('postal_code', '=', Auth::user()->postal_code)->first();
     if ($barrio) {
         Session::put('barrio', $barrio);
     } else {
         Session::forget('barrio');
     }
     $data = [];
     $data['general'] = 1;
     $data['dashboardAuth'] = 1;
     return view('frontend.account.profile', $data);
 }
 /**
  * Function to register or authenticated with facebook
  * @param  Request $request
  * @return $user
  */
 public function postProvider(Request $request)
 {
     // Rules for server side validations
     $rules = ['email' => ['required', 'email'], 'first_name' => ['required'], 'last_name' => ['required'], 'provider_id' => ['required'], 'avatar_standar' => ['required'], 'avatar_thumbnail' => ['required']];
     $data = $request->all();
     $validator = app('validator')->make($data, $rules);
     if ($validator->fails()) {
         throw new DingoException\StoreResourceFailedException('Error data', $validator->errors());
     }
     //Check user in database
     $user = $this->user->findByUserNameOrCreateFromApp($data);
     //Create token
     $token = JWTAuth::fromUser($user);
     $user = $user->toArray();
     $user['token'] = $token;
     $user['barrio'] = '';
     if (isset($user['postal_code'])) {
         $barrio = Barrio::where('postal_code', '=', $user['postal_code'])->first();
         if ($barrio) {
             $user['barrio'] = $barrio->name;
         }
     }
     return $user;
 }