Laravel 5.6上的Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException

时间:2018-07-30 04:30:01

标签: php laravel

我尝试在Laravel 5.6中创建一个登录页面,它显示以下错误

Symfony \组件\ HttpKernel \ Exception \ MethodNotAllowedHttpException

我已将POST方法用于路由,但服务器显示了相同的错误  截图相同。 enter image description here

视图代码

    <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' => 'yourname@example.com', '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::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";
            }

        }

    }

预先感谢

1 个答案:

答案 0 :(得分:0)

您需要像下面那样更改视图代码,

<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' => 'yourname@example.com', '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>

您只需要在Form::open()外观中提供方法类型,例如'method'=>'post',默认为GET