Custom complete registration with form in laravel

 First you create view blade form in view folder

  <form method="POST" action="{{ route('company/registration') }}">
                                {{ csrf_field() }}
                                <div class="form-group {{ $errors->has('username') ? ' has-error' : '' }}">
                                    <label>User Name</label>
                                    <input id="name" type="name" class="form-control" placeholder="User Name" name="username" value="{{ old('username') }}" required
                         autofocus>
                          @if ($errors->has('username'))
                          <span class="help-block">
                                <strong>{{ $errors->first('username') }}</strong>
                                    </span>
                          @endif
                                </div>
                               
                                <div class="form-group {{ $errors->has('email') ? ' has-error' : '' }}">
                                    <label>Email Id</label>
                                    <input id="email" type="email" class="form-control" placeholder="Email" name="email" value="{{ old('email') }}" required>
                                     @if ($errors->has('email'))
                                 <span class="help-block">
                                        <strong>{{ $errors->first('email') }}</strong>
                                    </span>
                                 @endif
                                </div>
                                <div class="form-group {{ $errors->has('password') ? ' has-error' : '' }}">
                                    <label>Password</label>
                                    <input id="password" type="password" class="form-control" placeholder="Password" name="password" required>
                                     @if ($errors->has('password'))
                                   <span class="help-block">
                                        <strong>{{ $errors->first('password') }}</strong>
                                    </span>
                                  @endif
                                </div>
                                <div class="form-group">
                                    <input type="checkbox" name="item"  >
                                    <label>
                                         Agree the terms and policy
                                    </label>
                                   
                                </div>
                                <button type="submit" class="btn btn-primary btn-flat m-b-30 m-t-30">Register</button>
                               
                                <div class="register-link m-t-15 text-center">
                                    <p>Already have account ? <a href="{{url('company/login')}}"> Sign in</a></p>
                                </div>

                            </form>


You may  create your own page according you i have create a sample page

create routes in laravel 

for using to route first view the page and second is post the data 

The route is look like this

Route::get('company/registration', 'Auth\CompanyRegistrationController@companyRegistrationForm');

Route::post('company/registration', 'Auth\CompanyRegistrationController@CompanyRegistration')->name('company/registration');

'companyRegistrationForm.php' is a controller to call the view if you want direct call the view using only route but security purpose i am using controller to call the view look like this

 public function companyRegistrationForm()

    {

    return view('company/company-registraion');

    }

After call the view page if you write the page submit code 

 public function CompanyRegistration(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([
                                    'user_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');   
            } 
         
   
     }

CompanyRegistration is function to accept the request value and check the validation .if condition is true then check email is already exist or not if email is exist to flash the msg . other wise go head and create the new userd according your condition


Custom complete registration with form in laravel Custom complete registration with form in laravel Reviewed by Bugs Solutions on December 19, 2020 Rating: 5

2 comments