Because of this: $postId = $postInformation['id'];
so you are trying to get $postInformation['id'] which does not exists there.
Try this dd($postInformation); and make sure that your array data contains all the data you need.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have this to get some info from an API:
$postInformation = (new postInformation)->handle(['field' => 'slug', 'value' => $this->slug]);
$postId = $postInformation['id'];
Then I have this:
$data =
array_map(fn ($category) => [
'post_id' => $postId,
'category_id' => $category['id'],
'category_name' => $category['name']['en'],
], $postInformation['categories']['data'], ['category_id', 'category_name']);
DB::table('post_categories ')->insertOrIgnore($data);
But it shows an error when I refresh the page:
{message: "Undefined array key "id"", exception: "ErrorException",…} exception: "ErrorException" file: "/var/www/html/app/Nova/Post.php" line: 59 message: "Undefined array key \"id\"" trace: [{,…}, {file: "/var/www/html/app/Nova/Postl.php", line: 59,…},…].
If I hardcode the $postId like, " $postId = 5;" it shows:
file: "/var/www/html/app/Nova/Post.php"
line: 69
message: "Undefined array key \"categories\""
Please or to participate in this conversation.