获得在同一会话中使用rest api创建的元素的ID

问题描述 投票:0回答:1

我正在使用其余api在论坛上创建消息:

  $point = '/forums/topics';
  $endpoint = $url. 'api'. $point. '?key='. $apiKey;

  $options = [
               'form_params' => [
                 'forum' => 3,
                 'title' => $request->title,
                 'post' => $request->body,
                 'author' => 1
               ]
 ];
 $client = new Client();
 $request =  $client->post($endpoint, $options);

通过此API,我需要创建ID才能将其存储在$ article-> id_topic中

但是我不知道如何返回使用POST创建的项目的ID。

我已经做过一些测试,失败了,这里有一些:

$article->id_topic = $request->id;

和json_decode

 $id_topic = json_decode($request);
 $idt = $request->id;

 $articoli->id_topic = $idt;
php api
1个回答
0
投票
 $id_topic = json_decode($request->getBody());
 $article->id_topic = $id_topic->id;
 $article->save();
相关问题
热门问答
最新问题