Laravel 使用Route对象从控制器方法内部获取路由参数是否被认为是一种不好的做法?[拉威尔]

Laravel 使用Route对象从控制器方法内部获取路由参数是否被认为是一种不好的做法?[拉威尔],laravel,laravel-6,Laravel,Laravel 6,我有多条路由解析为单个控制器方法。我使用Route来获取路由参数,因为Laravel按照定义的顺序将参数传递给方法。尽管路由方法有效,但它增加了单元测试的复杂性。有什么建议吗 <?php // routes/api.php $router->get('/test/{another_example_param}', ['uses' => 'ExampleController@show']); $router->get('/test/{example_param}/thi

我有多条路由解析为单个控制器方法。我使用
Route
来获取路由参数,因为Laravel按照定义的顺序将参数传递给方法。尽管
路由
方法有效,但它增加了单元测试的复杂性。有什么建议吗

<?php

// routes/api.php

$router->get('/test/{another_example_param}', ['uses' => 'ExampleController@show']);
$router->get('/test/{example_param}/thing/{another_example_param}', ['uses' => 'ExampleController@show']);
$router->get('/testing/{example_param}', ['uses' => 'ExampleController@show']);

由于这是一个相当开放的问题,您能说明它是如何使您的单元测试复杂化的吗?您检查过这个吗?由于这是一个相当开放的问题,您能说明它是如何使您的单元测试复杂化的吗?您检查过这个吗?
<?php

// ExampleController.php

use Illuminate\Routing\Controller
use Illuminate\Routing\Route;

class ExampleController extends Controller {
  // Explicitly defining route parameters
  public function show(string $example_param, string $another_example_param) {
    echo "example param: $example_param";
    echo "another_example param: $another_example_param";
  }  

  // Extracting route params from Route approach
  public function showAlternate(Route $route) {
    $example_param = $route->example_param;
    $another_example_param = $route->another_example_param;

    echo "example param: $example_param";
    echo "another_example param: $another_example_param";    
  }  
}