public function storeVideo(Request $input, $id) { //Validates the input from the create event page $this->validate($input, ['title' => 'required|max:20', 'link' => 'required|max:50|unique:videos']); //Assigns each value from the form to a variable. $title = $input->input('title'); $link = $input->input('link'); //Changes link to embed url if (strlen($link) > 11) { if (preg_match('%(?:youtube(?:-nocookie)?\\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\\.be/)([^"&?/ ]{11})%i', $link, $match)) { $link = $match[1]; } else { return false; } } //Updates the users table with the data from the form. Video::insert(['userid' => Auth::user()->id, 'eventid' => $id, 'title' => $title, 'link' => $link]); return redirect('past/pastDetails/' . $id . '#video'); //redirects to events view when finished }