public function saveCandidate() { $validator = Validator::make(Input::all(), array('name' => 'required', 'email' => 'required|email')); // check for the required fields before doing anything else if ($validator->fails()) { return Redirect::back()->withInput()->withErrors($validator->messages()); } // Check to see if we already have a candidate at this email address. There can be only one $email = Input::get('email'); $existingCandidates = Candidate::where('email', '=', $email)->first(); if ($existingCandidates) { $messageBag = new Illuminate\Support\MessageBag(); $messageBag->add('error', "You have already registered as a candidate, please log in."); return Redirect::back()->withErrors($messageBag); } $c = new Candidate(); $name = explode(' ', Input::get('name')); $name = $name[0]; // Prep client data for save $c->email = Input::get('email'); $c->name = $name; $c->surname = $name[1]; $c->password = Hash::make(Input::get('password')); $c->current_position = Input::get('current_position'); $c->phone = Input::get('phone'); $c->sendjobs = Input::get('sendjobs', 0); if (Input::hasFile('cv')) { $newfilename = Str::slug($name) . '_cv_' . uniqid() . '.' . Input::file('cv')->getClientOriginalExtension(); Input::file('cv')->move(public_path() . '/uploads/cvs/', $newfilename); $c->cv = $newfilename; // Send email to KDC Candidate::sendBecomeCandidate(Input::all(), $newfilename); } else { // Send email to KDC Candidate::sendBecomeCandidate(Input::all(), ''); } $c->save(); // Send activation email Candidate::sendActivation($c->id); // Add the candidate to the session - using this rather than full on auth as that's already being used by admins to access the CMS (dashboard) // Session::put('candidate', $c); // Just take them to the front page again for now. return Redirect::to('/')->with('info', 'Thank you for your registration – we’ll send you your login details as soon as we can.'); }