Last active
April 11, 2020 22:37
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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, | |
] | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Full tutorial on Laravel authentication here: https://employbl.com/blog/user-approval-laravel-artisan-welcome-email