【发布时间】:2017-05-06 23:47:19
【问题描述】:
在我的 Laravel routes/web.php 文件中,我定义了以下两条路线:
Route::get('transaction/{id}', ['uses' => 'PaynlTransactionController@show'])->name('transaction.show');
Route::get('transaction/{txId}', ['uses' => 'PaynlTransactionController@showByTxId'])->name('transaction.showByTxId');
在我的RouteServicesProvider 中,我定义了以下两种模式:
Route::pattern('id', '[0-9]+');
Route::pattern('txId', '/^(TX(1[0-9]\d|[2-9]\d\d)-(1[0-9]\d\d\d\d|[2-9]\d\d\d\d\d))$/');
每当我转到transaction/<id> 时,只要id 是一个整数,路由就会正常工作。但是,例如,当我转到transaction/TX874-152268 时,它与任何路由都不匹配,我收到NotFoundHttpException in RouteCollection.php 错误。
我已经验证了 txId 正则表达式,它给出了一个完整的匹配:https://regex101.com/r/kDZR4L/1
我的问题:为什么只有我的id 模式工作正常,而我的txId 模式却不行?
【问题讨论】:
-
@WiktorStribiżew 谢谢,我试过但没有运气。它看起来好多了:-)
标签: php laravel pattern-matching laravel-5.3