user3352042
user3352042

Reputation: 131

Laravel 5.5, cant pass data after validation

i have this validation for registering new users but every time I submit it just reloads and stays in the page, I am lost, but when I use the Registration::create($request->all()) without validation from the top it pushes through and saves the data. please help

my controller

      namespace App\Http\Controllers;

      use Illuminate\Http\Request;
      use App\Registration;


      class RegistrationsController extends Controller
      {
          public function index(){

              return view('registrations.create');

          }
          public function store(){

              request()->validate([
                  'name' => 'required|string|max:255',
                  'email' => 'required|string|email|max:255|unique:users',
                  'password' => 'required|string|min:6|confirmed',
              ]);

              $validatedUser = Registration::create([
                  'name' => request('name'),
                  'email' => request('email'),
                  'password' => bcrypt(request('password'))
              ]);

              return redirect()->home();

          }
      }

here is my create.blade

             <form action="{{ route('registrations.store') }}" method="POST">

                         {{ csrf_field() }}

                              <div class="form-group">
                                <label for="">Full Name</label>
                                <input type="text" class="form-control" name="name" id="name" aria-describedby="helpId" placeholder="Juan Dela Cruz">
                                <small id="helpId" class="form-text text-muted">Ex. Juan Dela Cruz</small>
                              </div>

                              <div class="form-group">
                                <label for="">Password</label>
                                <input type="password" class="form-control" name="password" id="password" placeholder="type password here..">
                              </div>

                              <div class="form-group">
                                <label for="">Confirm password</label>
                                <input type="password" class="form-control" name="password_confirm" id="password_confirm" placeholder="type password here..">
                              </div>

                              <div class="form-group">
                                <label for="">Email address</label>
                                <input type="email" class="form-control" name="email" id="email" aria-describedby="emailHelpId" placeholder="[email protected]">
                                <small id="emailHelpId" class="form-text text-muted">Must be valid email address</small>
                              </div>

                              <button type="submit" class="btn btn-primary">Submit</button>


                     </form>

for my route i just used Route::resource

thank you

Upvotes: 0

Views: 639

Answers (1)

Rafik Tighilt
Rafik Tighilt

Reputation: 2101

This is probably because your password confirmation fails. Your confirmation field must be named : password_confirmation and not password_confirm as the documentation say :

The field under validation must have a matching field of foo_confirmation. For example, if the field under validation is password, a matching password_confirmation field must be present in the input.

Upvotes: 2

Related Questions