Php Laravel-表格POST方法问题
我对laravel框架相当陌生 问题是我在单击表单按钮时定义了一个简单的控制器tp函数 我的表格是Php Laravel-表格POST方法问题,php,laravel,post,Php,Laravel,Post,我对laravel框架相当陌生 问题是我在单击表单按钮时定义了一个简单的控制器tp函数 我的表格是 <form url="{{ action('loginController@login') }}" method="POST"> <input type="text" name="username" /> <input type="password" name="password"/> <label
<form url="{{ action('loginController@login') }}" method="POST">
<input type="text" name="username" />
<input type="password" name="password"/>
<label class="checkbox">
<input type="checkbox" value="remember-me" id="rememberMe" name="rememberMe"> Remember me
</label>
<button type="submit">Login</button>
</form>
loginController.php
public function login(Request $req)
{
echo 'blah';
}
问题是,当我点击按钮时,除了一个错误外,什么也没有发生
Whoops, `looks like something went wrong.`
有人能帮忙吗
注:已检查其他类似问题,但没有任何进展。如果有人能帮忙,我们将不胜感激
泰
编辑:
我的堆栈跟踪有点
NotFoundHttpException in compiled.php line 8912:
in compiled.php line 8912
at RouteCollection->match(object(Request)) in compiled.php line 8264
at Router->findRoute(object(Request)) in compiled.php line 8212
at Router->dispatchToRoute(object(Request)) in compiled.php line 8207
at Router->dispatch(object(Request)) in compiled.php line 2419
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in compiled.php line 3286
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in compiled.php line 9963
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in compiled.php line 9948
at Pipeline->then(object(Closure)) in compiled.php line 2366
at Kernel->sendRequestThroughRouter(object(Request)) in compiled.php line 2350
at Kernel->handle(object(Request)) in index.php line 54
在routes.php中,登录路径中缺少一个qoute。应该是这样的-
Route::post('/login', 'loginController@login');
你能用这个替换你的代码吗-
<form action="{{ url('login')}}" method="POST">
{!! csrf_field() !!}
<input type="text" name="username" />
<input type="password" name="password"/>
<label class="checkbox">
<input type="checkbox" value="remember-me" id="rememberMe" name="rememberMe"> Remember me
</label>
<button type="submit">Login</button>
</form>
希望这将对您有所帮助。FYI,您缺少CSRF令牌-{{CSRF_field}}请先在表单中添加此标记,转到.env文件并将APP_DEBUG设置为true。然后再次提交表单-您应该看到问题的具体原因,而不是一般标题。这是一个POST-submit,所以可能是您抛出了一个令牌失配异常。请看。{csrf_field}}已在表单中。我没有在这里引用它。Sorry如果您可以发布堆栈跟踪,请按照LessugarApp_debug的指示启用调试模式,并将其设置为true。但是除了上面提到的错误之外,也没有其他错误。您确定缺少一个报价吗?你能再检查一下吗?@HarindaSamarasekara:你现在遇到了什么问题?@jaysingkar:请检查这个-Route::post'/login,loginController@login';对不起,实际上我查了你的路线,你错过了一个报价。现在更正
<form action="{{ url('login')}}" method="POST">
{!! csrf_field() !!}
<input type="text" name="username" />
<input type="password" name="password"/>
<label class="checkbox">
<input type="checkbox" value="remember-me" id="rememberMe" name="rememberMe"> Remember me
</label>
<button type="submit">Login</button>
</form>