[英]Laravel 5.6 MethodNotAllowedHttpException when user is logged out but sending a post request
我正在使用Sentinel進行身份驗證。 只要我登錄,一切就可以正常進行。 但是,當我注銷(刪除persistences
表中的所有值)並且我在something.blade.php
,然后單擊觸發發布請求的link
(請參見下面的代碼片段)時,我將轉到登錄名頁。 登錄后,出現以下Laravel錯誤:
Symfony \\組件\\ HttpKernel \\異常\\ MethodNotAllowedHttpException
在web.php
路由:
Route::post('something/{xtype}/{xid}/execute/{yid}', 'MyController@execute');
MyController.php
控制器邏輯:
public function execute($xtype, $xid, $yid)
{
// business logic
return back();
}
查看something.blade.php
:
<form action="/something/{{ $something->xtype }}/{{ $something->xid }}/execute/{{ $others->yid }}" method="POST" id="y_{{ $others->yid }}">
{!! csrf_field() !!}
</form>
<a type="button" href="#" onClick="document.getElementById('y_{{ $others->yid }}').submit()">
中間件AdminMiddleware.php
:
public function handle($request, Closure $next)
{
if (Sentinel::check())
{
if (Sentinel::getUser()->roles()->first()->slug == 'admin')
{
return $next($request);
}
}
return redirect()->guest('/login')
->with(['error' => "You do not have the permission.."]);
}
}
編輯:
登錄后,我將進入LoginController
並執行以下代碼:
return redirect()->intended($fallbackUrl);
由於我還不熟悉Laravel,因此很難在框架內部進行調試。 您有什么想法/建議嗎?
一切都歡迎! 提前致謝!
當您嘗試發布到為獲取請求或其他方法設置的URL時,會出現此錯誤。 您需要朝那個方向檢查!
在表格上沒有指定方法,而在路線上則指定了路線應使用哪種類型的方法
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.