/** * Store a newly created resource in storage. * * @return Response */ public function store() { // Fetch all request data. $data = Input::only('title', 'extra_url', 'event_id'); $event_id = Input::get('event_id'); // Build the validation constraint set. $rules = array('title' => array('required', 'min:3'), 'extra_url' => array('required', 'Url'), 'event_id' => array('required', 'integer', 'sometimes')); // Create a new validator instance. $validator = Validator::make($data, $rules); if ($validator->passes()) { $extra = new Extra(); $current_user = Sentry::getUser(); if ($current_user->hasAccess('admin') || $current_user->hasAccess('verified')) { $extra->approved = '1'; } $extra->author_id = Sentry::getUser()->id; $extra->title = Input::get('title'); $extra->extra_url = Input::get('extra_url'); $extra->save(); $event = ep\Event::find($event_id); $event->eventExtra()->save($extra); return Redirect::to('/event/' . $event->slug)->with('global_success', 'Event submitted successfuly!'); } return Redirect::to('/event/' . $event->slug)->withInput()->withErrors($validator)->with('message', 'Validation Errors!'); }
} else { return Redirect::guest('login'); } }); /* |-------------------------------------------------------------------------- | Author check |-------------------------------------------------------------------------- | | Checks if currently logged in user is author of a resource. Based on URL segment. | */ Route::filter('authorEvent', function () { if (Sentry::check()) { $event_id = Request::segment(3); $event_author = ep\Event::find($event_id)->author_id; $current_user = Sentry::getUser(); if ($current_user->id == $event_author || $current_user->hasAccess('admin')) { } else { return Redirect::to('/')->with('global_error', 'This is restricted area. You shall not pass.'); } } else { return Redirect::guest('login'); } }); Route::filter('authorShow', function () { if (Sentry::check()) { $show_id = Request::segment(3); $show_author = Show::find($show_id)->author_id; $current_user = Sentry::getUser(); if ($current_user->id == $show_author || $current_user->hasAccess('admin')) {
public function unfavourite($id) { $user = Sentry::getUser(); $event = ep\Event::find($id); $fav_check = $event->eventUser()->where('user_id', '=', $user->id)->first(); if ($fav_check == false) { return Redirect::to(URL::to('/'))->with('global_error', 'This event doesn\'t exists in your favourites.'); } else { $event->eventUser()->detach($user); return Redirect::to(URL::previous())->with('global_success', 'Event has been removed from favourites.'); } }