您可以通过多种方式与视图共享数据。它不限于 1 或 2 个参数。您可以共享无限的参数。
选项1
$categories = ProductCategory::all();
$brands = ProductBrand::all();
$product = Product::first();
return view('product.edit', compact(['categories', 'brands', 'product']));
选项 2
$categories = ProductCategory::all();
$brands = ProductBrand::all();
$product = Product::first();
return view('product.edit', ['categories' => $categories, 'brands' => $brands, 'product' => $product]);
选项 3
$categories = ProductCategory::all();
$brands = ProductBrand::all();
$product = Product::first();
return view('product.edit')->with('categories', $categories)->with('brands', $brands)->with('product', $product);