Laravel模型的绑定基于五参数而不是尿液段
我有像这样的路线
Route::match(['GET'], 'banana/{id}', 'BananaController@view');
Route::bind('id', function ($id): ?Banana
{
return Banana::findOrFail($id);
});
中,我将具有不错的模型绑定,
public function view(Banana $banana)
{
return view('view', [
'banana' => $banana,
]);
}
,在这样的控制器
https://bananas.com/banana/666
但是我需要在URL上使用此操作,
https://bananas.com/banana?id=666
如何使用Get-参数而不是URI片段进行此模型绑定?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最好的选择可能是添加一条获取路线并直接检索查询。
可以在下面找到更多信息:
Your best bet is probably adding a GET route and retrieving the query directly.
More information can be found below:
https://laravel.com/docs/9.x/requests#retrieving-input-from-the-query-string