laravel posting null in mysql Workbench while connection seems fine

  laravel, mysql, php

i am new to laravel and was watching a tutorial on creating an authentication form with login and register. I’m stuck on the posting of the form as the form submits but returns null values in the database I’ve tried previous solutions with no luck
Im i doing something wrong? below is acode preview.

Controller File

<?php

namespace AppHttpControllersAuth;

use AppModelsUser;
use IlluminateHttpRequest;
use AppHttpControllersController;
use IlluminateSupportFacadesHash;

class RegisterController extends Controller
{
    public function index() 
    {
        return view ('auth.register');
    }

    public function store(Request $request)
    {
        //Validation
        $this->validate($request, [
            'username' => 'required|max:255',
            'email' => 'required|email|max:255',
            'password' => 'required|confirmed',
            'location' => 'required|max:255',
        ]);
        
        //Store User
        User::create([
            'username' => $request->username,
            'email' => $request->email,
            'password' => Hash::make($request->password),
            'location' => $request->location,
        ]);

registration form

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta name="google-signin-client_id" content="407063748479-dbmn68b26gcbeln4hevvcr97qnrg6hrd.apps.googleusercontent.com">
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="https://kit.fontawesome.com/64d58efce2.js" crossorigin="anonymous"></script>
    <link rel="stylesheet" href="../assets-Authenticate/css/RegistrationStyling.css" />
    <title>Sign in & Sign up Form</title>

  </head>

  <body>

    <div class="container">
      <div class="forms-container">
        <div class="signin-signup">

          <!--Sign In Form-->
          <form action="#" class="sign-in-form" method="POST">
            @csrf
            <h2 class="title">Sign in</h2>
            <div class="input-field">
              <i class="fas fa-user"></i>
              <input type="text" placeholder="User Email" required/>
            </div>
            <div class="input-field">
              <i class="fas fa-lock"></i>
              <input type="password" placeholder="Password" required  pattern="(?=.*d)(?=.*[a-z])(?=.*[A-Z]).{8,}" title="Must contain at least one number and one uppercase and lowercase letter, and at least 8 or more characters" />
            </div>
            <input type="submit" value="Login" class="btn solid" />
            <div class="reset">
             <a href="PasswordReset.html">Forgot Password ?</a>
            </div>
            <p class="social-text">Or Sign in with social platforms</p>
            <div id="my-signin2"></div>
            <script>
              function onSuccess(googleUser) {
                console.log('Logged in as: ' + googleUser.getBasicProfile().getName());
              }
              function onFailure(error) {
                console.log(error);
              }
              function renderButton() {
                gapi.signin2.render('my-signin2', {
                  'scope': 'profile email',
                  'width': 240,
                  'height': 50,
                  'longtitle': true,
                  'theme': 'dark',
                  'onsuccess': onSuccess,
                  'onfailure': onFailure
                });
              }
            </script>

            <script src="https://apis.google.com/js/platform.js?onload=renderButton" async defer></script>
          </form>

          <!--Sign Up Form-->
          <form action="#" class="sign-up-form" method="POST">
            @csrf
            <h2 class="title">Sign up</h2>
            <div class="input-field">
              <i class="fas fa-user"></i>
              <input type="text" name="username" id="username" placeholder="Username" required />
            </div>
            <div class="input-field">
              <i class="fas fa-envelope"></i>
              <input type="email" name="email" id="email" placeholder="Email" required />
            </div>
            <div class="input-field">
              <i class="fas fa-lock"></i>
              <input type="password" name="password" id="password" placeholder="Password"  onkeyup="checkPassword()" required pattern="(?=.*d)(?=.*[a-z])(?=.*[A-Z]).{8,}" title="Must contain at least one number and one uppercase and lowercase letter, and at least 8 or more characters" />
            </div>
            <div class="input-field">
              <i class="fas fa-lock"></i>
              <input type="password" id="passwordConfirm" placeholder="Password Confirm" onkeyup="checkPassword()" required pattern="(?=.*d)(?=.*[a-z])(?=.*[A-Z]).{8,}" title="Must contain at least one number and one uppercase and lowercase letter, and at least 8 or more characters" />
            </div>
            <div class="">
              <p id="message"></p>
            </div>
            <div class="input-field">
              <i class="fas fa-map-marker-alt"></i>
              <input type="text" name="location" id="location" placeholder="Location" required/>
            </div>
            <input type="submit" class="btn" value="Create" onclick="checkPassword()" />
          </form>

        </div>
      </div>

web.php route

<?php

use IlluminateSupportFacadesRoute;
use AppHttpControllersAuthRegisterController;

Route::get('/register',[RegisterController::class, 'index' ])->name('register');
Route::post('/register',[RegisterController::class, 'store' ]);

Route::get('/layouts', function() {
    return view('layouts.index');
});

Source: Laravel

Leave a Reply