title: Laravel array index variable won't pass to redirected view
body: <p>My $data['orders'] won't pass to my redirected view and i get the error &quot;Undefined index: orders (View: /.../pages/userhome.blade.php)&quot;. For some reason the $data['user'] variable will pass and show its value but the 'orders' one will not. Ive changed the name and why way i create the data array but its still won't work.</p>
  <p>pagescontroller.php</p>
  <pre><code>        $this-&gt;validate($request, []);
          $data = array();
          $orderdate = date('Y-m-d H:i:s');
          $data['user'] = Auth::user();
          $ordernum = Str::uuid()-&gt;toString();
          $sum = 0;
  
          $cart = DB::table('cart')-&gt;where('buyerid', '=', auth()-&gt;user()-&gt;id)-&gt;paginate(10);
  
          foreach ($cart as $item) {
  
              $product = Product::find($item-&gt;itemid);
              $orderitem = new Orderitem;
              $orderitem-&gt;buyerid = $item-&gt;buyerid;
              $orderitem-&gt;productid = $product-&gt;id;
              $orderitem-&gt;quantity = $item-&gt;quantity;
              $orderitem-&gt;ordernumber = $ordernum;
              $orderitem-&gt;dateordered = $orderdate;
              $sum = $sum + (number_format($product-&gt;price * $item-&gt;quantity, 2));
              $product-&gt;sold = $product-&gt;sold + $item-&gt;quantity;
              $orderitem-&gt;save();
          }
  
          $order = new Order;
          $order-&gt;buyerid = Auth::user()-&gt;id;
          $order-&gt;customeremail = Auth::user()-&gt;email;
          $order-&gt;customeraddress = ''; //$request-&gt;input('address');
          $order-&gt;total = number_format($product-&gt;price * $item-&gt;quantity, 2);
          $order-&gt;dateordered = $orderdate;
          $order-&gt;city = ''; //$request-&gt;input('city');
          $order-&gt;zipcode = ''; //$request-&gt;input('zipcode');
          $order-&gt;ordernumber = $ordernum;
          $order-&gt;total = $sum;
          $order-&gt;save();
  
          $orders = DB::table('orders')-&gt;where('buyerid', '=', auth()-&gt;user()-&gt;id)-&gt;get();
          $data['orders'] = $orders;
  
          return redirect(&quot;/userhome/{$data['user']-&gt;name}&quot;)-&gt;with('success', 'Your order has been sent. A confirmation will be sent to your email shortly.')-&gt;with(compact($data));
  </code></pre>
  <p>userhome.blade.php
  the code fails right at the '@if(count($data['orders']) &gt; 0)' line</p>
  <pre><code>&lt;h1&gt;{{ $data['user']-&gt;name }}&lt;/h1&gt;
  
      &lt;section class=&quot;topsellers&quot;&gt;
          &lt;h2&gt;Orders&lt;/h2&gt;
          &lt;div class=&quot;container flex&quot;&gt;
  
              @if (count($data['orders']) &gt; 0)
                  @foreach ($data['orders'] as $order)
  
                      &lt;div class=&quot;productcard&quot; }&gt;
                          &lt;p&gt;test&lt;/p&gt;
  
                      &lt;/div&gt;
  
                  @endforeach
  
              @else
                  &lt;p&gt;Looks like you have no current orders.&lt;/p&gt;
  
              @endif
  
          &lt;/div&gt;
          {{-- {{$data['products']-&gt;links()}} --}}
      &lt;/section&gt;
  </code></pre>