Skip to content

Instantly share code, notes, and snippets.

@connor11528
Last active April 11, 2020 22:37
Show Gist options
  • Save connor11528/0c5907c3f6ab71978f54872a6fd461d1 to your computer and use it in GitHub Desktop.
Save connor11528/0c5907c3f6ab71978f54872a6fd461d1 to your computer and use it in GitHub Desktop.
the store method on the candidate controller for saving users to the Employbl database
<?php
//...
class CandidateController extends Controller
{
// ...
/**
* @param Request $request
* @return \Illuminate\Http\JsonResponse
*/
public function store(Request $request)
{
$request->validate([
'first_name' => 'required',
'last_name' => 'required',
'email' => 'email|required|unique:users',
'linkedin_url' => 'required|url',
'phone_number' => 'numeric|digits:10|nullable',
'work_authorization' => 'required',
'city' => 'required',
'state' => 'required'
]);
$candidate = new User($request->all());
$candidate->active = false;
$candidate->save();
Mail::to($candidate->email)
->send(new CandidateRequestAccessConfirmationEmail($candidate));
Mail::to('[email protected]')
->send(new CandidateInfoEmail($candidate));
// todo: subscribe them to the newsletter
// https://github.com/spatie/laravel-newsletter
return response()->json(
[
'message' => self::$CANDIDATE_SUCCESS_MESSAGE,
'candidate' => $candidate,
]
);
}
}
@connor11528
Copy link
Author

Full tutorial on Laravel authentication here: https://employbl.com/blog/user-approval-laravel-artisan-welcome-email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment