routes - Laravel 隐式 Binding 多于两个字的路由

我们知道 Laravel 8 及更高版本在其 routes 上有一个隐式 Binding 函数。我试图创建一个模型名称为 QuestionHelper 的控制器资源。当我使用 Route 资源定义路由时,如下所示

use App\Http\Controllers\QuestionHelperController;

Route::resource('questionhelper', QuestionHelperController::class);

不幸的是,隐式 binding 函数不适用于 show、edit、update 和 delete 方法。例如,当我访问显示页面时,隐式 binding 中的数据为空。

// When I access this method, the $questionHelper variable is empty
public function show(QuestionHelper $questionHelper)
{
    return view('questionhelper.show', compact('questionHelper'));
}

或者当我使用编辑页面中包含的更新方法访问编辑方法时显示错误。

Illuminate\Routing\Exceptions\UrlGenerationException
Missing required parameter for [Route: questionhelper.update] [URI: admin/questionhelper/{questionhelper}] [Missing parameter: questionhelper]. (View: /var/www/resources/views/questionhelper/edit.blade.php)

为什么会这样?而在其他模型中,例如只有一个词的类别,效果很好。

谢谢你。

回答1

/**
     * $parameter, is $id;
     *
    **/

    <a href="{{ route('questionhelper.update', $parameter)}}"></a>

回答2

我解决了。

如果模型名称超过 2 个单词(在这种情况下为 QuestionHelper),那么基本上我们需要将资源名称命名为 questionHelper 而不是 questionhelper

嗯我以前不知道

相似文章

webrtc - WebRTC: CoTurn 不能中继流

我们在云虚拟机上设置CoTurn。然后我们使用我们的WebRTC演示网站对其进行测试。我们发现它不能中继流,这意味着WebRTC演示的两端在不同子网中时无法相互连接。根据调查,做了以下工作:我们在Ub...

c# - NotifyOfPropertyChange 不刷新 map 中的数据

更改从组合框中选择的报告后刷新数据时出现问题。在ViewModel本身中,数据会发生变化,但视图不会刷新。建议我做错了什么?或者我应该改进什么?一开始,数据加载良好并且map是彩色的,唯一的问题是更改...

随机推荐

最新文章