0
votes

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

1
There is no CSRF token in your form.Jagdeesh Kumar
is that mandatory ?Raymond Thomas
yes it is mandatory, use {{csrf_token()}} in your formrkj
It is used there in meta tag <meta name="csrf-token" content="{{ csrf_token() }}" />Raymond Thomas
@RaymondThomas that meta tag doesn't have to do with how the form functions in anyway ... sidenote, might want to close the formlagbox

1 Answers

0
votes

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