这样做是设置Location
标题,如源代码所示:
/**
* Respond with a created response and associate a location if provided.
*
* @param null|string $location
*
* @return \Dingo\Api\Http\Response
*/
public function created($location = null, $content = null)
{
$response = new Response($content);
$response->setStatusCode(201);
if (! is_null($location)) {
$response->header('Location', $location);
}
return $response;
}
因此,在您的示例中,由于您正在创建一个新用户,您可以将用户个人资料页面作为位置发送,例如:
return $this->response->created('/users/123');
至于内容,正如您在函数中看到的那样,它将设置返回的内容。在您的情况下,它可能是带有新用户信息的 json 字符串,例如:
return $this->response->created('/users/123', $user); // laravel should automatically json_encode the user object