0

Good Day, I am new in Laravel environment. I am developing a simple school enrollment registration website but having trouble in validation on my controller..

My plan is, when the user will register in the website, username textbox should be validated if the username is already used by other student. i tried every possible tutorial i found in the net but i have no luck...

Here is my page, red circle should be validated if the input username already exist in the database.. enter image description here

Whole code in .blade

           <!--Registration  start here -->
           <form method="Post" action="{{url('store_account_Registration')}}">
            @csrf 
           
            @if(Session::get('success'))
             <div class="alert alert-danger">
                 {{ Session::get('success')}}
             </div>
            @endif

            @if(Session::get('fail'))
             <div class="alert alert-danger">
                 {{ Session::get('fail')}}
             </div>
            @endif
           <div class="col-sm-12 form-group">
              <input type="hidden" class="form-control" name="uniqID3" id="uid" placeholder="Enrollment Registration Number"  value="{{ $regid3 }}" >
           </div>
           <div class="col-sm-12 form-group">
             <input type="hidden" class="form-control" name="pfulname3" id="name-f" placeholder="Enrollment Registration Number" required value="{{ $fulname4 }}" >
           </div>
           <div class="container-fluid" style="margin-bottom: 2em">
            <div class="row justify-content-center align-items-center" style="padding: 10px">
               <div class="card col-md-5" style="transform: none;>
               
                     <div class="card-body">
                        <div class="alert alert-primary" role="alert" style="margin-top: 1em">
                          <p>Name: <strong>{{ $fulname4 }}</strong></p>
                          <p>Enrollment No.: <strong>{{ $regid3 }}</strong></p>
                        </div>
                         
                            <input type="hidden" class="hide" id="csrf_token" name="csrf_token" value="C8nPqbqTxzcML7Hw0jLRu41ry5b9a10a0e2bc2">
                            <div class="row">
                                    <div class="col-md-12">
                                      <div class="form-group">
                                        <label>Username</label>
                                        <div class="input-group">
                                          <div class="input-group-prepend">
                                            <span class="input-group-text"><i class="fa fa-user" aria-hidden="true"></i></span>
                                          </div>
                                          <input type="text" class="form-control" name="username" id="username" placeholder="Username" required value="{{ old('username')}}"  >
                                         
                                        </div>
                                        <div class="help-block with-errors text-danger">
                                          <span style="color:red">@error('username'){{ $message}}@enderror</span>
                                        </div>
                                      </div>
                                    </div>
                            </div>
                            <div class="row">
                                  <div class="col-md-12">
                                    <div class="form-group">
                                      <label>Password</label>
                                      <div class="input-group">
                                        <div class="input-group-prepend">
                                          <span class="input-group-text"><i class="fa fa-lock" aria-hidden="true"></i></span>
                                        </div>
                                        <input type="password" id="password" name="password" pattern="^\S{6,}$" onchange="this.setCustomValidity(this.validity.patternMismatch ? 'Must have at least 6 characters' : ''); if(this.checkValidity()) form.password_two.pattern = this.value;" class="form-control"  title="Password is needed" required placeholder="Password" >
                                        
                                      </div>
                                      <div class="help-block with-errors text-danger">
                                        <span style="color:red">@error('password'){{ $message}}@enderror</span>
                                      </div>
                                    </div>
                                  </div>
                            </div>
                            <div class="row">
                                <div class="col-md-12">
                                  <div class="form-group">
                                    <label>Confirm Password</label>
                                    <div class="input-group">
                                      <div class="input-group-prepend">
                                        <span class="input-group-text"><i class="fa fa-lock" aria-hidden="true"></i></span>
                                      </div>
                                      <input id="password_two" type="password" name="password_two" pattern="^\S{6,}$" onchange="this.setCustomValidity(this.validity.patternMismatch ? 'Please enter the same Password as above' : '');" placeholder="Confirm Password" class="form-control"  title="Confirm Password is needed" required placeholder="Confirm Password" >
                                      
                                    </div>
                                    <div class="help-block with-errors text-danger">
                                      <span style="color:red">@error('password_two'){{ $message}}@enderror</span>
                                    </div>
                                  </div>
                                </div>
                          </div>
                            
                            <div class="row" style="margin-top: 1em" >
                              <div class="col-md-12" style="margin-bottom: 2em">
                                <input type="hidden" name="redirect" value="">
                              <!--  <button type="submit" class="btn btn-primary btn-lg btn-block" name="submit">Save OASIS Account</button> -->
                               <!--  < <a href="enrollment_success"><p class="btn btn-primary btn-lg btn-block">Save OASIS Account</p></a> -->
                                <button type="submit" class="btn btn-primary btn-lg btn-block">Save OASIS Account</button> 
                              </div>
                            </div>
                         
                      </div>
             </div>
          </div>
        </div>
           <!--Registration  start here -->
        
    
        </div>
      </form> 
enter code here

I always got this error.. enter image description here

Here is my code..

  1. my validation in my controller enter image description here public function store_account_Registration(Request $request) {

     request()->validate([
         'username' => 'required|min:6|unique:TempAccount,AccountName,'
     ]);
    

    // $this->validator($request->all())->validate();

     $current_date = date('Y-m-d H:i:s');
     $query = DB::table('TempAccount')->insert([
             'RegID'=>$request->input('uniqID3'),
             'FullName'=>$request->input('pfulname3'),
             'AccountName'=>$request->input('username'),
             'Pass'=>$request->input('password'),
             'created_at'=> $current_date,
             'updated_at'=> $current_date,
    
     ]);
    
    
    
     if($query){
         return back()->with('success', 'Data has been Successfyll inserted');
    
      //   return view('pages.enrollment_success');
    
    
        // return redirect()->route('pages.enrollment_GradeLevelSchoolInfo', ['uniqIDd' => 1]);
      //  return redirect('enrollment_GradeLevelSchoolInfo');
    
     }
     else
     {
         return back()->with('fail', 'something went wrong');
     }
    

    }

  2. my Route in web.php enter image description here

Route::get('pages',[accountregistration::class, 'index']); Route::Post('store_account_Registration', [accountregistration::class, 'store_account_Registration']);

  1. my action in form.. enter image description here
0

1 Answer 1

0

The issue is in your form. You are not reaching the correct route at all.

Also you are missing the @csrf token or at least not shown in your print screen

<form action="{{url('store_account_Registration')}}" method="POST">
 @csrf 

In your validation you can remove the trailing coma after AccountName as well.

Sign up to request clarification or add additional context in comments.

6 Comments

i already tried this Sir but same error... <form method="post" action="{{url('store_account_Registration')}}"> @csrf
And you get the same error? Run php artisan optimize to clear routes/cache. Your error is a route issue irrelevant with any validation or something.
Paste your whole form code. This should work so there is something in your form breaking it.
Yeah as i mentioned above something in the next lines break your form. Please include your whole form or a bigger part than this one line.
Can you try this: <form action="{{ route('store_account_Registration') }}" method="post"> Exactly as is, just copy paste it. Also you have another error in your form. Check this line: <div class="card col-md-5" style="transform: none;> You are missing a second double quote: <div class="card col-md-5" style="transform: none";>
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.