コード例 #1
0
ファイル: ShowController.php プロジェクト: Belar/eventpotion
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     // Fetch all request data.
     $data = Input::only('title', 'show_icon', 'games', 'stream', 'people', 'vods', 'start_date', 'about', 'tags');
     // Build the validation constraint set.
     $rules = array('title' => array('required', 'min:3'), 'show_icon' => array('required', 'alpha_dash'), 'games' => array('required'), 'start_date' => array('required', 'date'), 'people' => array('required'), 'about' => array('max:21800'), 'stream' => array('alpha_dash'), 'vods' => array('max:21800'));
     // Create a new validator instance.
     $validator = Validator::make($data, $rules);
     if ($validator->passes()) {
         $current_user = Sentry::getUser();
         $show = new Show();
         $show->author_id = $current_user->id;
         $title = Input::get('title');
         $uniqid = str_shuffle(uniqid());
         $show->slug = Str::slug($title, '-') . '-' . $uniqid;
         $show->title = $title;
         $show->show_icon = Input::get('show_icon');
         $show->air_date = new DateTime(Input::get('start_date'));
         $show->people = Input::get('people');
         $show->about = Input::get('about');
         $show->vods = Input::get('vods');
         $show->tags = Input::get('tags');
         if ($current_user->hasAccess('admin') || $current_user->hasAccess('verified')) {
             $show->approved = '1';
         }
         $show->save();
         $games = Input::get('games');
         foreach ($games as $game) {
             $game_id = Game::find($game);
             $show->showGame()->attach($game_id);
         }
         if ($stream_url = trim(Input::get('stream'))) {
             $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->streamShow()->attach($show);
             } else {
                 if (!$show->showStream($stream_old->id)->first()) {
                     $stream_old->streamShow()->attach($show);
                 }
             }
         }
         return Redirect::to('/')->with('global_success', 'Show submitted successfuly!');
     }
     return Redirect::to('/show/add')->withInput()->withErrors($validator)->with('message', 'Validation Errors!');
 }