【发布时间】:2021-02-01 20:50:55
【问题描述】:
我手动创建了一些用于自定义目的的路线。
这是我的代码:
Route::post('/dashboard/show-all-notifications', [App\Http\Controllers\DashboardController::class, 'showAllNotifications']);
表格
{!! Form::open(['method'=>'POST','action'=>['App\Http\Controllers\DashboardController@showAllNotifications']]) !!}
{!! Form::submit('Show all notifications', ['class'=>'btn btn-sm btn-primary btn-block']) !!}
{!! Form::close() !!}
仪表板控制器
public function showAllNotifications(Request $request)
{
if($request->isMethod('post'))
{
$notifications = Auth::user()->notifications;
return view('dashboard.showAllNotifications',compact('notifications'));
}
else
{
return abort(404);
}
}
当我在浏览器中输入 URL(GET request) 时,它向我显示了这个错误,但它在 POST / PATCH / DELETE 表单请求上工作。如果请求是GET,我需要类似的东西,返回到404 not found.
有人知道这个错误的解决方法吗?
【问题讨论】:
标签: laravel routes controller