Search code examples
phplaravellaravel-http-client

Can I get lastInsertId value after Http Client Post request?


On laravel site making Http Post request I need to get id of the l;ast inserted ID, like:

$response = Http::withToken($this->token)->post(route('articles.store'), [
    'title'        => 'Item Title lorem',
    'text'         => 'Item Text lorem',
    'text_shortly' => 'Item Text shortly lorem',
    'published'    => true,
]);

$lastItemId = DB::getPdo()->lastInsertId(); // this value is 0

New value is added and I see sql insert statement in sql logs, but $lastItemId is zero...

Can I to get this value somehow ?

"laravel/framework": "^9.19",
"guzzlehttp/guzzle": "^7.2",

Thanks in advance!


Solution

  • you can select id from the last row

    Article::select('id')->latest();