【发布时间】:2019-02-24 00:46:43
【问题描述】:
在 Laravel 中,我希望能够通过 id 或名称搜索用户。
我有以下路线:
Route::get('/user/{id}', 'UserController@getUserById')->name('user_by_id');
在浏览器中是这样的:
http://localhost:8000/user/1
如您所见,从 url 无法确定传递的值是 id 还是 name。
所以,我要求的可能是? 符号之后的 url 参数。
我想要以下网址:
http://localhost:8000/user?id=1
http://localhost:8000/user?name=hans
但我从来没有发现有人提到这个问题。
这可能吗? 如果不是,或者不是最佳实践,如何正确处理?
【问题讨论】:
标签: laravel