0

In my controller I currently give 2 parameters to the view like this:

return view('home')->with(['listings'=>$listings, 'featured_listings'=>$featured_listings]);

But when I add a third parameter it gives me the following message:

Too few arguments to function App\Http\Controllers\HomeController::index(), 0 passed and exactly 1 expected

Is there any way to give more than 2 parameters to a view from a controller?

Zain
  • 37,492
  • 7
  • 60
  • 84
Max
  • 357
  • 1
  • 6
  • 16

3 Answers3

2

This very simple to pass data to view more than one. There are many ways to pass data to view. I suggest you

return view('home',compact('listings','featured_listings','your_data',...));
A.A Noman
  • 5,244
  • 9
  • 24
  • 46
0

If you can put parameter like

return view('home', [
        'listings' => $listings, 
        'featured_listings' => $featured_listings,
        ..............................
]);

then you can put more than 2.

Senthurkumaran
  • 1,738
  • 2
  • 19
  • 29
0

There are few ways you can share data with a view. It is not limited to 1 or 2 parameters. You can share unlimited parameters.

Option 1

$categories = ProductCategory::all();
$brands = ProductBrand::all();
$product = Product::first();

return view('product.edit', compact(['categories', 'brands', 'product']));

Option 2

$categories = ProductCategory::all();
$brands = ProductBrand::all();
$product = Product::first();

return view('product.edit', ['categories' => $categories, 'brands' => $brands, 'product' => $product]);

Option 3

$categories = ProductCategory::all();
$brands = ProductBrand::all();
$product = Product::first();

return view('product.edit')->with('categories', $categories)->with('brands', $brands)->with('product', $product);
devzakir
  • 387
  • 3
  • 15