/** * Store a newly created song in storage. * * @return Response */ public function store() { // Set rules for validator $rules = array("artist" => "required", "title" => "required", "requester" => "required", "link" => "required|url"); // Validate input $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { // TODO: Remember form input... return Redirect::to('song/create')->withErrors($validator, "song"); } // Create new song $song = Input::all(); // Set or unset remember cookie if (isset($song['remember-requester'])) { $cookie = Cookie::make("requester", $song['requester']); } else { $cookie = Cookie::forget("requester"); } $artist = DB::getPdo()->quote($song['artist']); $title = DB::getPdo()->quote($song['title']); if (Song::whereRaw("LOWER(artist) = LOWER({$artist}) AND LOWER(title) = LOWER({$title})")->count() > 0) { return Redirect::to('song/create')->with('error', "HEBBEN WE AL!!!")->withCookie($cookie); } Song::create($song); // Set success message $msg = "Gefeliciteerd! Je nummer is aangevraagd :D"; // Redirect to song index page with message and cookie return Redirect::to("/")->with("success", $msg)->withCookie($cookie); }