简体   繁体   English

Laravel:如何为命名路由覆盖路由助手功能

[英]Laravel: How to override route helper function for a named route

I have working on predeveloped Laravel-5.x project and I need to change lots of URLs from: 我正在开发预先开发的Laravel-5.x项目,我需要从以下位置更改许多URL:

route('product.show', ['id'=> $product->id), 'title' => $product->title])

to

route('product.show', ['id'=> encode_id($product->id), 'title' => slug_title($product->title)])

If I don't want replace all the 'product.show' routes to new version, is there any way to override route helper function for 'product.show' to generate new URL? 如果我不想将所有“ product.show”路由替换为新版本,是否有任何方法可以覆盖“ product.show”的路由帮助程序功能以生成新的URL?

Function route() defined in the \\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\helpers.php \\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\helpers.php定义的函数route()

It is defined without any namespace thus it can be called anywhere. 它没有任何名称空间定义,因此可以在任何地方调用。 Obviously you can overwrite it in your project for example in the AppServiceProvider or RouteServiceProvider . 显然,您可以在项目中覆盖它,例如在AppServiceProviderRouteServiceProvider

But I recommend you to use your custom function with some namespace that you should specify in the file(s) that you need. 但是我建议您将自定义函数与应在所需文件中指定的某些名称空间一起使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM