替换调度的路由参数
Replace route parameter for dispatch
使用 RESTful 资源控制器让我可以做到这一点:
$request = Request::create(route('api.v1.booking.show'), 'GET');
而解码生成的URL是:
http://example.app/api/v1/booking/{booking}
我知道我可以发出 GET 请求并解析参数调用
Route::get($request, function($booking) {
return $some_id;
});
但在我的例子中,我想使用调度方法转发请求:
return Route::dispatch($request);
我不知道如何在调用 dispatch
方法时解析参数,因为它不像 get
方法那样接受闭包。
除了使用 PHP 的 str_replace
之外,还有 Laravel 方法吗?
为了给路由的 {booking} 参数设置一个值,您需要传递一个路由参数数组作为 route() 的第二个参数:
$request = Request::create(
route('api.v1.booking.show', ['booking' => $bookingId]),
'GET'
);
使用 RESTful 资源控制器让我可以做到这一点:
$request = Request::create(route('api.v1.booking.show'), 'GET');
而解码生成的URL是:
http://example.app/api/v1/booking/{booking}
我知道我可以发出 GET 请求并解析参数调用
Route::get($request, function($booking) {
return $some_id;
});
但在我的例子中,我想使用调度方法转发请求:
return Route::dispatch($request);
我不知道如何在调用 dispatch
方法时解析参数,因为它不像 get
方法那样接受闭包。
除了使用 PHP 的 str_replace
之外,还有 Laravel 方法吗?
为了给路由的 {booking} 参数设置一个值,您需要传递一个路由参数数组作为 route() 的第二个参数:
$request = Request::create(
route('api.v1.booking.show', ['booking' => $bookingId]),
'GET'
);