John Davidson

php - Too few arguments to function App\Http\Controllers\ProduitController::show()

0 comments
Message:


I wants to show users list into my dashboard pannel but it shows me this problem :


Too few arguments to function App\Http\Controllers\ProduitController::show(), 0 passed in C:\wamp64\www\Ecommerce\vendor\laravel\framework\src\Illuminate\Routing\Controller.php on line 54 and exactly 1 expected

Controller File :


public function show($id)
{
$produit = Produit::find($id);
return view('produits', compact('produit'));
}

blade file :


@foreach($produits as $produit)
<div class="product__item__pic set-bg" data-setbg="{{ asset('img/uploads/'.$produit->image)}}">
<ul class="product__item__pic__hover">
<li><a href="#"><i class="fa fa-heart"></i></a></li>
<li><a href="#"><i class="fa fa-retweet"></i></a></li>
<li><a href="#"><i class="fa fa-shopping-cart"></i></a></li>
</ul>
</div>
<div class="product__item__text">
<h6><a href="#">{{ $produit->designation }}</a></h6>
<h5>{{ $produit->prix_uni }} Mad</h5>
</div>
@endforeach

Route :


Route::get('/produits','ProduitController@show');


My Answer:
The issue is with your route definition. You need to pass the parameter in the route definition to match the parameter expected in the controller method.

Change your route definition to include the parameter like this:

php
Route::get('/produits/{id}','ProduitController@show');


This way, when you access the `/produits/{id}` route, Laravel will pass the `id` parameter to the `show` method in your `ProduitController`.

Make sure to also update your blade file to pass the `id` parameter when accessing the route.

Rate this post

5 of 5 based on 1846 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us