【发布时间】:2020-02-17 08:33:22
【问题描述】:
我希望创建更漂亮的 URL,但在创建有效路由时遇到问题:
假设我有以下页面http://localhost/app/account/5/edit。
这适用于 Route::get('account/{account}', 'AccountController@edit');
如果我修改 Account Model 并将 getRouteKeyName 修改为 return 'name',我可以(使用上面相同的 Route ) 访问以下链接:http://localhost/app/account/randomName/edit
问题是,我对一条稍微不同的路线感兴趣,即:http://localhost/app/account/randomName-5/edit
如果我创建一个路由 Route::get('/accounts/{ignore}-{account}/edit', 'AccountController@edit'),它会因为发送的第一个参数而失败要编辑的是字符串,而不是 Account 的实例。这可以通过将 edit(Account $ac) 修改为 edit($ignored, Account $ac); 轻松解决……但感觉就像在作弊。
有没有办法让路由忽略第一个 {block}?
【问题讨论】: