Nikki
443
4
Laravel

Getting an invoice number to be generated

Posted 4 months ago by Nikki

I'm trying to generate an invoice number, but I'm getting null. I think I'm missing something but I'm not sure what it is.

Here is the invoiceNumber() code in my helpers.php

function invoiceNumber()
    {
        $orders = App\Order::all();

        if($orders->isEmpty())
        {
            $invoice = 'arm0001';
            return $invoice;
        }

        foreach($orders as $order)
        {
            $latest = App\Order::latest()->first();

            if($latest->order == true)
            {
                $invoice = 'arm'.$latest->order+1;
                return $invoice;
            }
        }
    }

and this is where I'm trying to get it to be taken

public function deliveryConfirmation()
{
    $menus_child = Menu::where('menu_id', 0)->with('menusP')->get();
    $contacts = Contact::all();

    if(!Session::has('cart'))
    {
        return view('public.shopping-cart', compact('menus_child', 'contacts'));
    }

    $oldCart = Session::get('cart');
    $cart = new Cart($oldCart);

    $invoice_number = invoiceNumber();
    dd($invoice_number);

    return view('public.delivery-confirmation', ['products' => $cart->items, 'totalPrice' => $cart->totalPrice, 'menus_child' => $menus_child, 'contacts' => $contacts, 'invoice_number' => $invoice_number]);
}

Please sign in or create an account to participate in this conversation.