我设计一个RESTful应用程序,我想管理的URL参数,此刻我在控制器此功能为GET该列表中的所有资源API/V1 /猫:Laravel REST风格的URL参数处理
public function index()
{
$cats = Cats::all();
foreach ($cats as $cat) {
$requirement->view_requirement = [
'href' => 'api/v1/cat/' . $cat->id,
'method' => 'GET'
];
}
$response = [
'msg' => 'List of all Cats',
'cats' => $cats
];
return response()->json($response, 200);
}
和路线是:
Route::group(['prefix' => 'v1'], function() {
Route::resource('cats', 'CatController', [
'except' => ['edit', 'create']
]);
这与管理网址的最佳方式,例如搜索参数,如:?API/V1 /猫的名字=菲利普&颜色=黑色
也有这种方式,我喜欢:'$请求 - > filter' – louisfischer
和' request() - > filter'太^^ –