我正在创建一个接受帖子请求的API端点。成功的发布请求包括具有值的令牌。如果存在此标记,则在我的数据库表中创建记录。一旦完成,就没有其他功能可以调用。可以用消息返回die()响应吗?邮件请求是从移动应用程序发送的,实际上并不需要响应。我想知道什么是最佳做法?
public function create(Request $request, Response $response)
{
$params = $request->getParsedBody();
if (!isset($params['token'])) {
die("No token was provided.");
}
try {
$device = Device::create(['token' => $params['token']]);
die("Device with token {$device->token} has been registered.");
} catch (\Illuminate\Database\QueryException $e) {
die("There was a problem registering this device. Error code: {$e->errorInfo[1]}.");
}
}