Jo *_*lge 1 ajax json request laravel laravel-6.2
我使用 Postman 在 Laravel Api 中发送请求,并且返回一个空数组。而且我不知道为什么?
\n\n我的路线:
\n\nRoute::middleware('auth:api')->group( function () {\n\n Route::resource('reservations', 'ReservationController');\n});\nRun Code Online (Sandbox Code Playgroud)\n\n我的预订控制器:
\n\n <?php\n\nnamespace App\\Http\\Controllers;\n\nuse Illuminate\\Http\\Request;\nuse App\\Http\\Requests\\ReservationCreateRequest;\nuse App\\Repositories\\ReservationRepository;\nuse App\\Http\\Resources\\Reservation as ReservationResource;\n\nclass ReservationController extends BaseController\n{\n\n protected $entrepriseRepository;\n\n public function __construct(ReservationRepository $reservationRepository)\n {\n $this->reservationRepository = $reservationRepository;\n }\n\n /**\n * Display the specified resource.\n *\n * @param int $id\n * @return \\Illuminate\\Http\\Response\n */\n public function show($id)\n {\n $reservation = $this->reservationRepository->getById($id);\n\n return $this->sendResponse(new ReservationResource($reservation), 'Reservation');\n }\n\n /**\n * Update the specified resource in storage.\n *\n * @param Illuminate\\Http\\Request $request\n * @param int $id\n * @return \\Illuminate\\Http\\Response\n */\n public function update(Request $request, $id)\n {\n $inputs = $request->all();\n\n if (!$reservation = $this->reservationRepository->update($id, $inputs))\n {\n return $this->sendError('Impossible de mettre \xc3\xa0 jour', $request->errors(), 400);\n }\n\n return $this->sendResponse(new ReservationResource($reservation), 'Reservation mise \xc3\xa0 jour avec succ\xc3\xa8s !' , 200);\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n如果我只返回一个响应
\n\nreturn response($request->all());\nRun Code Online (Sandbox Code Playgroud)\n\n我有一个空数组...
\n\n方法
\n\nshow($id)\nRun Code Online (Sandbox Code Playgroud)\n\n工作正常...
\n\n有人有什么建议吗?
\n如果您从邮递员发送PATCH请求,则需要将其发送,因为不幸的是,Laravel 为with请求x-www-form-urlencoded提供了空请求。form-dataPATCH
附带说明一下,您不能使用 发送文件,x-www-form-urlencoded因此如果您的请求中有文件,您应该在请求正文中POST使用form-data和发送请求_method: PATCH,Laravel 会自动将其视为PATCH请求。
| 归档时间: |
|
| 查看次数: |
3811 次 |
| 最近记录: |