RouteCollection.php第251行中的MethodNotAllowedHttpException:

时间:2017-05-31 16:55:51

标签: php laravel-5.4

AT login.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Creative - Bootstrap 3 Responsive Admin Template">
    <meta name="author" content="GeeksLabs">
    <meta name="keyword" content="Creative, Dashboard, Admin, Template, Theme, Bootstrap, Responsive, Retina, Minimal">
    <link rel="shortcut icon" href="img/favicon.png">

    <title>welcome</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/bootstrap-theme.css" rel="stylesheet">
    <link href="css/elegant-icons-style.css" rel="stylesheet" />
    <link href="css/font-awesome.css" rel="stylesheet" />
    <link href="css/style.css" rel="stylesheet">
    <link href="css/style-responsive.css" rel="stylesheet" />

</head>
  <body class="login-img3-body">
    <div class="container">
      <form class="login-form" method="post" action="{{ url('/dashboard') }}"> //{{ route('login') }}
      <input type="hidden" name="_token" value="{{ csrf_field() }} ">   

        <div class="login-wrap">
            <p class="login-img"><i class="icon_lock_alt"></i></p>
            <div class="input-group">
              <span class="input-group-addon"><i class="icon_profile"></i></span>
              <input type="text" name="Username" class="form-control" placeholder="Username" autofocus>
            </div>
            <div class="input-group">
                <span class="input-group-addon"><i class="icon_key_alt"></i></span>
                <input type="password" name="password" class="form-control" placeholder="Password">
            </div>
            <label class="checkbox">
                <input type="checkbox" value="remember-me"> Remember me
                <span class="pull-right"> <a href="#"> Forgot Password?</a></span>
            </label>
            <button class="btn btn-primary btn-lg btn-block" type="submit">Login</button>
            <button class="btn btn-info btn-lg btn-block" type="submit">Signup</button>
        </div>
      </form>
    <div class="text-right">
            <div class="credits">

                <a href="https://facebook.com/t.prakash.pokhrel/"> Developer::xxx</a> 
            </div>
        </div>
    </div>
  </body>
</html>

和web.php

Route::get('/' , ['as' => '/' , 'uses'=> 'loginController@getlogin']);
    Route::post('/login', ['as' => 'login', 'uses'=> 'loginController@postlogin']);


    Route::group(['middleware' =>['authen']], function () 
    {
    Route::get('/dashboard',['as'=>'dashboard', 'uses'=> 'dashboardController@dashboard']);
    Route::get('/logout' ,['as'=>'logout', 'uses'=> 'loginController@getLogout']);

});

我是laravel的新手。我发生了这个错误。如何解决和  method =“post”action =“{{url('/ dashboard')}}”&gt; // {{route('login')}}  “{{csrf_field()}}。在这里的url应该传递的动作字段...我的意思是目的地或相同的路径..我想重定向到仪表板..谢谢:)

2 个答案:

答案 0 :(得分:2)

尝试更改路线

首先,您需要在表单中设置登录路径网址(action =&#34; {{url(&#39; / login&#39;)}}&#34;)并在postlogin函数中提交表单后使用auth并检查电子邮件密码是否正确。如果正确,则重定向网址是仪表板。

答案 1 :(得分:0)

使用

检查您的路线预期 在终端中

php artisan route:list 命令 接下来将表单方法更改为

如果您希望用户重定向到仪表板,则需要在您的控制器中执行此操作

`class ProfileController extends Controller
 { 
     //your code here

 public dashbord(){

 // your code 

  return view("your dashboard view path");      
  }