laravel路由未定义,即使路由已定义



我的控制器中有这段代码。

public function courierUpdate(Request $request, $id)
{
$request->validate([
'current_location' => 'required',
]);
$courierInfoUpdate =CourierInfo::findOrFail($id);
$courierInfoUpdate->current_location = $request->current_location;

$courierInfoUpdate->save();
$notify[] = ['success', 'Courier location info has been updated'];
return back()->withNotify($notify);
}

我有一张表格,可以用来更新运输细节;

<div class="row mb-30">
<div class="col-lg-12 mt-2">
<div class="card border--dark">
<h5 class="card-header bg--dark">@lang('Courier Location')</h5>
<div class="card-body">
<form action="{{route('courier.Update')}}" method="POST">
@csrf
<div class="modal-body">
<div class="form-group">
<label for="current_location" class="form-control-label font-weight-bold">@lang('Current Location')</label>
<input type="text" class="form-control form-control-lg" name="current_location" value="{{__($courierInfo->current_location)}}" required="">
</div>



</div>
<div class="modal-footer">

<button type="submit" class="btn btn--primary"><i class="fa fa-fw fa-paper-plane"></i>@lang('Update')</button>
</div>
</form>

</div>
</div>
</div>
</div>

我还在web.php 中添加了路线

Route::post('/courier-Update','AppHttpControllersCourierSettingController@courierUpdate')->name('courier.Update');

但当我运行页面时,我会得到这个错误;

Route [courier.Update] not defined. (View: /home/somename/example.com/core/resources/views/admin/courier/details.blade.php)

当已清除路由缓存时;

Route::get('/clear', function(){
IlluminateSupportFacadesArtisan::call('optimize:clear');
});

但我仍然收到错误信息;

当我使用此代码检查生成的路由路径时;

Route::get('routes', function () {
$routeCollection = Route::getRoutes();
echo "<table style='width:100%'>";
echo "<tr>";
echo "<td width='10%'><h4>HTTP Method</h4></td>";
echo "<td width='10%'><h4>Route</h4></td>";
echo "<td width='10%'><h4>Name</h4></td>";
echo "<td width='70%'><h4>Corresponding Action</h4></td>";
echo "</tr>";
foreach ($routeCollection as $value) {
echo "<tr>";
echo "<td>" . $value->methods()[0] . "</td>";
echo "<td>" . $value->uri() . "</td>";
echo "<td>" . $value->getName() . "</td>";
echo "<td>" . $value->getActionName() . "</td>";
echo "</tr>";
}
echo "</table>";
});

我得到这条线,表明那个条路线存在;

POST    admin/courier-Update    admin.courier.Update    AppHttpControllersAdminAppHttpControllersCourierSettingController@courierUpdate

可能是什么问题?

您应该更换

route('courier.Update')

带有

route('admin.courier.Update')

因为那是你路线的全名。

您可能在将admin.前缀添加到路由名称的路由组中声明了路由。

最新更新