我想知道是否可以在laravel中为单个methode控制器创建多个根?像这样的东西:
//route
Route::get('foo/bar', 'FooController@bar');
Route::get('foo/bar/{id}', 'FooController@bar');
Route::get('foo/bar/{id}/{date}', 'FooController@bar');
//controller
class FooController extends Controller {
public function bar($id,$date)
{
//do something
}
}
答案 0 :(得分:1)
是的,但您必须处理空参数,例如:
cv::Mat aCameraImage = cv::Mat(cv::Size(getImageWidth(), getImageHeight()), CV_8UC1, getImageDataPtr());
if (!aCameraImage.empty())
{
cv::imshow("Camera Image", aCameraImage);
cv::waitKey(100);
}
for(int i = 0; i<aCameraImage.cols; i++ )
{
for(int j = 0; j<aCameraImage.rows; j++ )
{
std::cout << aCameraImage.at<uchar>(i,j) << " ";
}
std::cout << std::endl;
}
但是在这一点上,最好用可选参数声明单一路线:
public function bar($id=null, $date=null)
{
....