Home > other >  I'm pretty new to laravel and I'm doing user sign up and login but I'm getting an err
I'm pretty new to laravel and I'm doing user sign up and login but I'm getting an err

Time:06-20

The POST method is not supported for this route. Supported methods: GET, HEAD. I'm pretty new to laravel and I'm doing user sign up and login but I'm getting an error

This is the controller which is giving an error


namespace App\Http\Controllers;

use Illuminate\Http\facade;
use Request;
use DB;

class hotsmoke extends Controller
{
    function login() {

        return view('hot_smoke_login');

    }

    function signup() {

        return view('sign-Up');

    }

    function login2() {

        return view('dashboard');

    }

    function store() {

        $uname= Request::input('name');

        $uemail = Request::input('email');

        $unumber= Request::input('number');

        $uaddress= Request::input('address');

        $upass= Request::input('password');




        DB::unprepared("insert into customers (name, email,number,address,password) values ('$uname','$uemail','$unumber','$uaddress','$upass')");
         return redirect('/hot_smoke_login');

    }
    function match2() {

        $uemail = Request::input('email');

        $upass = Request::input('password');



        $loginData = DB::select('select password from users where email = ?', [$uemail]);

     

        if (count($loginData) > 0){

           

            foreach ($loginData as $tablepass) {



                if (($tablepass->password) == $upass){

                    return view('dashboard');

                }

                else{

                    $error='Password does not match';

                    return view('hot_smoke_login')->with('error',$error);

                }

            }

        }

    }


}

my blade view which is not running as mentioned

<!doctype html>
<html lang="en">

<head>
  <link rel="stylesheet" href="css/main.css">
  <link rel="stylesheet" href="css/login.css">
  <link rel="stylesheet" href="css/bootstrap.min.css">
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <title>Hotsmoke</title>
</head>

<body>
  <div >
    <div >
      <div  style=" height: 100vh; overflow: hidden;">
        <img src="images/hero-img.jpg" alt="" width="100%">
      </div>
      <div >
        <a href="javascript: history.go(-1)"><i ></i></a>
        <div >
          <h3 >Login to <strong style="color: #ce913a;">HotSmoke</strong></h3>
          <p >We know the cuisines and your taste better than anyone!</p>
          <form method="post" id="login">
            <div >
              <label  for="username">Email</label>
              <input type="text"  id="username">
            </div>
            <div >
              <label  for="password">Password</label>
              <input type="password"  id="password">
            </div>

            <div >
              <label ><span >Remember me</span>
                <input type="checkbox" checked="checked" />
                <div ></div>
              </label>
              <span ><a href="forget-password.html"  style="color: #e0ae66">Forgot
                  Password</a></span>
            </div>
            <a href="sign-Up.html" >Do not have an Account?</a>
            <small  id="error" style="display: none;"></small>
            <br><br>
            <button >Log In</button>
          </form>
        </div>
      </div>
    </div>
  </div>



  <script src="js/bootstrap.min.js"></script>
  <script src="https://kit.fontawesome.com/5e8b9def84.js" crossorigin="anonymous"></script>
  <script src="js/login.js"></script>
</body>

</html>

and my routes are

Route::get('sign-Up', [hotsmoke::class, 'signup']);
Route::post('sign-Up', [hotsmoke::class, 'store']);
Route::get('hot_smoke_login', [hotsmoke::class, 'login']);
Route::get('hot_smoke_login', [hotsmoke::class, 'match2']);

please guide me

CodePudding user response:

I hope this will work. In each an every input field add the name attribute and mention the name you want to call it.

For example <input type="text" name="username"> , do this to every input and after the form tag use @csrf token like this and the route name should be the action,

<form action="/sign-Up" method="post" id="login">
@csrf
...
</form>

CodePudding user response:

I think the first thing you need to do is add an 'action' attribute to your form element which points to the endpoint you want to submit the form to so in this case it will look like

action="{{ url('/sign-Up') }}"
  • Related