/** * Store a newly created resource in storage. * * @return Response */ public function store() { // Fetch all request data. $data = Input::only('title', 'event_icon', 'lan', 'games', 'website', 'brackets', 'ticket_store', 'vod', 'start_date', 'finish_date', 'prizepool', 'location', 'about', 'tags', 'public_state', 'streams'); // Build the validation constraint set. $rules = array('title' => array('required', 'min:3'), 'event_icon' => array('required', 'alpha_dash'), 'lan' => array('integer'), 'games' => array('required'), 'website' => array('url'), 'brackets' => array('url'), 'ticket_store' => array('url'), 'vod' => array('url'), 'start_date' => array('required', 'date', 'before:' . Input::get('finish_date')), 'finish_date' => array('required', 'date'), 'prizepool' => array('required', 'max:20'), 'location' => array('required_if:lan,true', 'max:25'), 'about' => array('max:21800'), 'public_state' => array('integer'), 'streams' => array('requiredOrArray', 'alpha_dashOrArray')); // Create a new validator instance. $validator = Validator::make($data, $rules); if ($validator->passes()) { $current_user = Sentry::getUser(); $event = new ep\Event(); $event->author_id = $current_user->id; $title = Input::get('title'); $uniqid = str_shuffle(uniqid()); $event->slug = Str::slug($title, '-') . '-' . $uniqid; $event->title = $title; $event->event_icon = Input::get('event_icon'); $event->website = Input::get('website'); $event->brackets = Input::get('brackets'); $event->ticket_store = Input::get('ticket_store'); $event->vod = Input::get('vod'); $event->start_date = new DateTime(Input::get('start_date')); $event->finish_date = new DateTime(Input::get('finish_date')); $event->prizepool = Input::get('prizepool'); $event->about = Input::get('about'); $event->tags = Input::get('tags'); if ($current_user->hasAccess('admin') || $current_user->hasAccess('verified')) { $event->approved = '1'; } $event->lan = Input::get('lan') ? 1 : 0; if (Input::get('lan') == true) { $event->location = Input::get('location'); $event->latitude = Input::get('latitude'); $event->longitude = Input::get('longitude'); } else { $event->location = 'Online'; } $event->public_state = Input::get('public_state') ? 1 : 0; $event->save(); $games = Input::get('games'); foreach ($games as $game) { $game_id = Game::find($game); $event->eventGame()->attach($game_id); } $stream_urls = Input::get('streams'); foreach ($stream_urls as $stream_url) { $stream_old = Stream::where('stream_url', '=', $stream_url)->first(); if ($stream_old == false && $stream_url) { $stream = new Stream(); $stream->stream_url = $stream_url; $stream->save(); $stream->streamEvent()->attach($event); } else { if (!$event->eventStream($stream_old->id)->first()) { $stream_old->streamEvent()->attach($event); } } } return Redirect::to('/')->with('global_success', 'Event submitted successfuly!'); } return Redirect::to('/event/add')->withInput()->withErrors($validator)->with('message', 'Validation Errors!'); }