我已经更新了get方法的代码,如下工作正常 招摇。
任何人都可以建议我使用laravel路线,控制器代码发布,放置,删除的swagger代码。 (正如我在GET中提到的那样)
路线/ web.php
Route::group(['prefix' => 'api/'], function () {
Route::get('dashboard', 'DashboardController@index');
});
DashboardController.php
* Display a listing of the resource.
*
* @return \Illuminate\Http\JsonResponse
*
* @SWG\Get(
* path="/api/dashboard",
* description="Returns dashboard overview.",
* operationId="api.dashboard.index",
* produces={"application/json"},
* tags={"dashboard"},
* @SWG\Response(
* response=200,
* description="Dashboard overview."
* ),
* @SWG\Response(
* response=401,
* description="Unauthorized action.",
* )
* )
*/
public function index(Request $request)
{
return response()->json([
'result' => [
'statistics' => [
'users' => [
'name' => 'Name',
'email' => 'user@example.com'
]
],
],
'message' => '',
'type' => 'success',
'status' => 0
]);
}
答案 0 :(得分:2)
狂欢邮件/投放/删除的Bellow laravel路线。
Route::post('/api/user', 'DashboardController@store');
Route::put('/api/user/{user_id}', 'DashboardController@edit');
Route::delete('/api/user/{user_id}', 'DashboardController@delete');
Route::get('/api/users', 'DashboardController@getData');
Route::get('/api/user/{user_id}', 'DashboardController@getDataById');
发布
/**
* @SWG\Post(
* path="/api/user",
* tags={"User"},
* operationId="ApiV1saveUser",
* summary="Add User",
* consumes={"application/x-www-form-urlencoded"},
* produces={"application/json"},
* @SWG\Parameter(
* name="name",
* in="formData",
* required=true,
* type="string"
* ),
* @SWG\Parameter(
* name="phone",
* in="formData",
* required=true,
* type="number"
* ),
* @SWG\Response(
* response=200,
* description="Success"
* ),
*/
投注
/**
* @SWG\Put(
* path="/api/user/{user_id}",
* tags={"User"},
* operationId="ApiV1UpdateUser",
* summary="Update User",
* consumes={"application/x-www-form-urlencoded"},
* produces={"application/json"},
* @SWG\Parameter(
* name="user_id",
* in="path",
* required=true,
* type="string"
* ),
* @SWG\Parameter(
* name="name",
* in="formData",
* required=true,
* type="string"
* ),
* @SWG\Response(
* response=200,
* description="Success"
* ),
*/
按ID删除
/**
* @SWG\Delete(
* path="/api/users",
* tags={"User"},
* operationId="ApiV1DeleteUser",
* summary="Delete User",
* @SWG\Parameter(
* name="user_id",
* in="path",
* required=true,
* type="string"
* ),
* @SWG\Response(
* response=200,
* description="Success"
* ),
*/
获取
/**
* @SWG\Get(
* path="/api/users",
* tags={"User"},
* operationId="ApiV1GetUsers"
* summary="Get Users",
* @SWG\Response(
* response=200,
* description="Success"
* ),
*/
获取ID
/**
* @SWG\Get(
* path="/api/user/{user_id}",
* tags={"User"},
* operationId="ApiV1GetUserById",
* summary="Get User by user id",
* @SWG\Parameter(
* name="user_id",
* in="path",
* required=true,
* type="string"
* ),
* @SWG\Response(
* response=200,
* description="Success"
* ),
*/
答案 1 :(得分:0)
我在以下链接中找到了发布,删除路由的代码参数
https://github.com/zircote/swagger-php/tree/master/Examples