使用url中的破折号控制多个参数

时间:2022-07-05 16:53:33

I am using laravel 5.0 framework and I have a route like this:

我正在使用laravel 5.0框架,我有这样的路由:

www.example.com/title-size

www.example.com/title-size

Where size is an optional parameter

其中size是可选参数

Route::any('embed-{title}-{size?}',['uses'=>'Posts@getData','as'=>'embed'])->where('title', '.*(?=-)');

Because my title contains dashes so it was ignoring my optional size parameter so I have researched and found this ->where('title', '.*(?=-)'); which is working good. Now the problem comes that I have to allways add size parameter. If no size parameter the route is not working so it gives me a 404.

因为我的标题包含短划线所以它忽略了我的可选大小参数所以我研究并发现了这个 - > where('title','。*(?= - )');这是有效的。现在问题来了,我必须总是添加大小参数。如果没有大小参数,路线不起作用,那么它给我一个404。

1 个解决方案

#1


1  

Please use Middleware as helper for your route. This is a standard in Laravel 5 and will help you achieve what you are looking for. Take a look at the basic examples from the /app/Http/Middleware/

请使用中间件作为路线的帮手。这是Laravel 5中的标准,将帮助您实现您的目标。看一下/ app / Http / Middleware /的基本示例

#1


1  

Please use Middleware as helper for your route. This is a standard in Laravel 5 and will help you achieve what you are looking for. Take a look at the basic examples from the /app/Http/Middleware/

请使用中间件作为路线的帮手。这是Laravel 5中的标准,将帮助您实现您的目标。看一下/ app / Http / Middleware /的基本示例