how to create simple registration with sending email in laravel all version?

 we will described code as below

 public function CRegistration(Request $request) {

         $rt['status'] = 'error';

          $data = $request->all();

            if(array_key_exists('item', $data))

            {   

          $v = Validator::make($data, [

                    'email' => 'required',

                    'username' => 'required',

                    'password' => 'required',

                   

        ]);

     

           if ($v->fails()) {

            

             $rt['code'] = '201';

            $rt['message'] = $v->errors()->toJson();

        }else {

            $user = User::where(["email"=> $data['email'],"role_type"=>2])->first();

               if(!empty($user)&& $user!=null){

              

                $rt['code'] = '201';

                $request->session()->flash('status', 'Email is already taken');

                $rt['message'] = 'Email is already taken';

                return view('company/company-registraion',compact('rt'));

            }

            else 

            {

              $user = User::create([

                                    'name' => $data['username'],

                                    'email' => $data['email'],

                                    'password' => bcrypt($data['password']),

                                    'role_type' => 2

                                    

                        ]);


                 if ($user) {

                            $rt['status'] = 'Successfully Registered';

                             $request->session()->flash('status', 'Successfully Registered');

                             $rt['code'] = '200';

                             $email=$data['email'];

                             return view('company/complete-company-registration',compact('email'));

                            //return redirect()->route('complete-company-registration');

                        }

                }

              }

            }

            else

            {

               

               $request->session()->flash('status', 'Please select terms and policy');   

            }  

        return view('company/company-registraion',compact('rt'));

     }


    First you make the registration function with request parameter

   get all the data in data variable after that check the validation if you want 

in above code we will also check the term and policy using this function (array_key_exists('item', $data) .

Next step check the validation is  using this function $v->fails() if condition is true then start next step 

  the next step is check user is available in database or not if available in database to flah the massage user is already exist otherwise create the user in the database.

if user registration is complete to show the successfully  msg or move the data other page is look like code

 return view('company/com-registraion',compact('rt'));

 

how to create simple registration with sending email in laravel all version? how to create simple registration with sending email in laravel all version? Reviewed by Bugs Solutions on December 13, 2020 Rating: 5

3 comments