你有下一条路线
Route::get('/{param1}',
'Http\Controllers\SomeController@getCollection');
Route::get('/{param_for_middleware}/{param1}',
'Http\Controllers\SomeController@getCollection');
而且,在我的控制器上,我有
// PSR7 code
use Illuminate\Routing\Controller;
use Psr\Http\Message\ServerRequestInterface;
class SomeController extends Controller
public function getCollection(ServerRequestInterface $request)
{
// here, I need access to param1
dd($request);
}
}
使用原始Laravel路由器我们可以使用$this->route()->parameters()['param1]
获得价值。但是,当我们在Laravel上使用PSR7时?
答案 0 :(得分:1)
你可以,仍然使用旧的方法吗?
public function getCollection(ServerRequestInterface $request, $param1)
{
// here is your param1!
dd($param1);
}
修改强>
如果您需要多个参数并且需要确保其位置,则可以执行以下操作:
public function getCollection(
ServerRequestInterface $request,
\Illuminate\Http\Request $illuminateRequest
)
{
// here is your param1 & param_for_middleware!
dd($illuminateRequest->route('param1') . ' & ' .
$illuminateRequest->route('param_for_middleware'));
}