Advertisement
Guest User

Untitled

a guest
Feb 26th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. export default{
  2. data(){
  3. return {
  4. form:{
  5. email:'',
  6. password:'',
  7. password_confirmation:'',
  8. fname:'',
  9. lname:'',
  10. city:''
  11. },
  12. formError:''
  13. }
  14. },
  15. methods:{
  16. //This should be a POST method through axios
  17. register:async function(){
  18. try{
  19. const res=await axios.post('api/register',this.form);
  20. console.log("Ba donnees : ",res.data);
  21. }catch(err){
  22. console.log("Erreeer",err.response);
  23. }
  24. }
  25. }
  26. }
  27.  
  28. private function validateForm($data){
  29. return Validator::make($data,
  30. [
  31. 'fname' => ['required', 'string','min:2' ,'max:255'],
  32. 'lname' => ['required', 'string','min:2' ,'max:255'],
  33. // 'mname' => ['string','min:2' ,'max:255'],
  34. 'company' => ['string','min:2' ,'max:255'],
  35. 'title' => ['string','min:2' ,'max:255'],
  36. 'phone_number' => ['string','min:13' ,'max:13'],
  37. 'city' => ['required', 'string','min:2' ,'max:100'],
  38. 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
  39. 'password' => ['required', 'string', 'min:8', 'confirmed']
  40. // 'password_confirm'=>['required','string']
  41. ]
  42. )->validate();
  43. }
  44. //Register
  45. public function register(Request $request){
  46. $data=$this->validateForm($request->all());
  47. $data['password']=Hash::make($data['password']);
  48. $user=new User($data);
  49. $user->save();
  50. return response()->json($user);
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement