0

I Have tried to create a login page in Laravel 5.6 it shows the following error

Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException

I have used the POST method for the routing but the server shows the same error screenshot of the same is added. enter image description here

The code of view

    <body>
    <div class="data-head">
        {{ Form::open(array('url' => 'login')) }}
        <p class="col-md-12">
            <h5 class="login-head">Login</h5>
        </p>
        <p>
            {{ $email_err }}
        </p>
        <p class="col-md-10 col-md-move">
            {{ Form::label('email', 'E-Mail Address', array('class' => 'awesome')) }}
            {{ Form::text('email','', array('placeholder' => '[email protected]', 'class' => 'form-control')) }}
        </p>
        <p class="col-md-10 col-md-move">
            {{ Form::label('password', 'Password', array('class' => 'awesome')) }}
            {{ Form::password('password', array('placeholder' => 'Password', 'class' => 'form-control')) }}
        </p>
        <p class="col-md-10 col-md-move">
            <a href="forget" class="link-forget">Forget Password ? </a>
            {{ Form::submit('Login', array('class' => 'btn btn-info')) }}
        </p>

    </div>
</body>

Route file:

    Route::post('/', function () {
    return view('welcome');
    });
    Route::post('register',function(){
        return view('login');
    });
    Route::post('login', 'LoginController@loginProcess');

The controller code

    namespace App\Http\Controllers;

    use Illuminate\Support\Facades\DB;
    use Illuminate\Http\Request;
    use Hash;

    class LoginController extends Controller
    {
        public function loginProcess(Request $request)
        {
            $email_err="";
            $password_err="";
            $pass="";
            $email = $request->input('email');
            $password = $request->input('password');
            $pass=DB::table('login')->where('email', $email)->value('password');
            if($pass=="")
            {
                $email_err="Non Registred User";
                return view('login',['email_error' => $email_err]);
            }
            if(Hash::check($password,$pass))
            {
                echo "Login Successs";
            }
            else
            {
                $password_err="Invalid Password";
            }

        }

    }

Thanks in advance

9
  • There is no CSRF token in your form. Commented Jul 30, 2018 at 4:33
  • is that mandatory ? Commented Jul 30, 2018 at 4:37
  • yes it is mandatory, use {{csrf_token()}} in your form Commented Jul 30, 2018 at 4:39
  • It is used there in meta tag <meta name="csrf-token" content="{{ csrf_token() }}" /> Commented Jul 30, 2018 at 4:46
  • @RaymondThomas that meta tag doesn't have to do with how the form functions in anyway ... sidenote, might want to close the form Commented Jul 30, 2018 at 4:49

1 Answer 1

0

You need to change code of view like below,

<body>
    <div class="data-head">
        {{ Form::open(array('url' => 'login','method' => 'post')) }}
        <p class="col-md-12">
            <h5 class="login-head">Login</h5>
        </p>
        <p>
            {{ $email_err }}
        </p>
        <p class="col-md-10 col-md-move">
            {{ Form::label('email', 'E-Mail Address', array('class' => 'awesome')) }}
            {{ Form::text('email','', array('placeholder' => '[email protected]', 'class' => 'form-control')) }}
        </p>
        <p class="col-md-10 col-md-move">
            {{ Form::label('password', 'Password', array('class' => 'awesome')) }}
            {{ Form::password('password', array('placeholder' => 'Password', 'class' => 'form-control')) }}
        </p>
        <p class="col-md-10 col-md-move">
            <a href="forget" class="link-forget">Forget Password ? </a>
            {{ Form::submit('Login', array('class' => 'btn btn-info')) }}
        </p>

    </div>
</body>

You just need to provide method type in Form::open() facade like 'method'=>'post' by default it is GET

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

5 Comments

No, it defaults to post "By default, a POST method will be assumed; however, you are free to specify another method:"
That is what understand from the documentation of Laravel 5.6
This package (Html Form Builder) isn't from Laravel .. it is a 3rd party package, so its not in those docs ... i suppose you mean an actual html form and how browsers handle html when the method isn't defined?
You mean Htmlcollective ?
laravelcollective maintains the html and form package

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.