Laravel 6 持久未定义变量错误

当我尝试访问我认为的变量时,遇到未定义的变量错误。我在这里经历了几种解决方案,但没有一个对我有用。我已经彻底检查了可能导致 mu 代码中出现此错误的所有内容,但根本找不到任何内容,请协助


控制器



namespace App\Http\Controllers;


use Illuminate\Http\Request;

use App\Product;

use App\Category;

use App\Depot;

use Illuminate\Support\Facades\DB;

use Gloudemans\Shoppingcart\Facades\Cart;

use Auth;


class CheckoutController extends Controller

{

    public function index()

    {

        $allcategories=Category::get();

        $delivery_method = DB::table('deliverymethods')

            ->get();

        $cartItems=Cart::content();

        return view('checkout.index',['delivery_method'=>$delivery_method],['allcategories'=>$allcategories]);

    }


    public function deliverymethod()

    {

        $cartItems=Cart::content();

        $allcategories=Category::get();

        return view('delivery.index',['cartItems'=>$cartItems],['allcategories'=>$allcategories]);

    }


    public function billinginfo()

    {

        $depots=Depot::get();

        $cartItems=Cart::content();

        $allcategories=Category::get();

        return view('billing.index',compact('cartItems'),['allcategories'=>$allcategories],['depots'=>$depots]);

    }


    public function shipping(Request $request)

    {

        $user_id=Auth::user()->id;

        $shippingaddress=DB::table('shippingaddresses')

                        ->select('shippingaddresses.*')

                        ->where('user_id',$user_id)

                        ->get();


        $cartItems=Cart::content();

        $allcategories=Category::get();

        return view('shipping.index',['cartItems'=>$cartItems],['allcategories'=>$allcategories],['shippingaddress'=>$shippingaddress]);

    }

}


繁华开满天机
浏览 117回答 1
1回答

莫回无

尝试将多个集合分组到一个数组中,然后将其发送到视图,如下所示:$viewData = [    'cartItems'  => $cartItems,    'allcategories'   => $allcategories,    'shippingaddress' => $shippingaddress];return View::make('shipping.index')->with($viewData);
打开App,查看更多内容
随时随地看视频慕课网APP