If you are just storing the cart as a multidimensional array, I would suggest using the product ID as the array key, so in the above code snippet, your keys would be 1 and 2 rather than 0 and 1. And flatten it by one level.
Then when an item is added you can test array_key_exists and act accordingly:
// Retrieve the product ID from the request
$productId = request('product_id');
// Retrieve the cart from the session
$cart = session()->get('cart');
// Update quantity if item already exists
if (array_key_exists($productId, $cart)) {
$cart[$productId]['quantity'] += 1;
} else {
// Add new product to cart
$cart[$productId] = [
'id' => $productId,
'quantity' => 1,
// ...
];
}
// Store cart back to session
session(['cart' => $cart]);
Note this is a very naïve implementation. In real world usage, you would most likely have a cart object stored in the session with the ability to specify quantities explicitly, remove items, etc.