Beispiel #1
0
 /**
  * Handle an incoming request.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Closure                 $next
  *
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     // If the user isn't logged in or they are part of a different city
     // deny access, otherwise go for it. Might be worth adding a message to
     // explain what happened on redirect.
     $city = City::findByIATA($request->route()->getParameter('city'))->first();
     if ($this->auth->guest()) {
         if ($request->ajax()) {
             return response('Unauthorized.', 401);
         } else {
             Notification::error('You need to be logged in to view that.');
             return redirect()->guest('auth/login');
         }
     } else {
         if ($city && $this->auth->user()->city_id !== $city->id) {
             Notification::error('You don\'t have permissions for that city.');
             if ($request->ajax()) {
                 return response('Unauthorized.', 401);
             } else {
                 return redirect('/' . $city->iata);
             }
         }
     }
     return $next($request);
 }
 /**
  * Reverse the migrations.
  *
  * @return void
  */
 public function down()
 {
     $city = City::findByIATA('nyc')->first();
     $event = Event::where('city_id', '=', $city->id);
     $city->delete();
     $event->delete();
 }
Beispiel #3
0
 /**
  * Update the specified resource in storage.
  *
  * @param \Illuminate\Http\Request $request
  * @param Event                    $event
  *
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $iata)
 {
     // dont let the request go through unless the user matches the city id.
     // This ^ should be a middleware.
     $city = City::findByIATA($iata)->first();
     $this->validate($request, ['name' => 'required', 'iata' => 'unique:cities,iata,' . $city->iata . ',iata', 'twitter_consumer_key' => 'required', 'twitter_consumer_secret' => 'required', 'twitter_access_token' => 'required', 'twitter_access_token_secret' => 'required']);
     $city->fill(Input::all());
     $city->save();
     return redirect('/' . $city->iata)->with('message', 'City details updated');
 }
Beispiel #4
0
 /**
  * Returns all events in with time_end in the future.
  *
  * @return Collection A collection of Events
  */
 public static function futureEventsByCityIATA($city_code)
 {
     $city = City::findByIATA($city_code)->first();
     return self::futureEvents()->where('city_id', '=', $city->id);
 }