Tuesday, March 14, 2017

LARAVEL - Show product by id at single product page

I have a problem showing just one product at the single product page. so if I click a product now at the front page I want to see that specific product. now I am seeing all products instead of the product I clicked!

this is the route:

Route::get('/product/{id}', [
    'uses' => 'productController@getProduct',
    'as' => 'product.single'
]);

This is the Controller:

public function getProduct($id)

    {
        $product = Product::find($id);
        return view('pages.product', ['id' => $product->id]);
    }

This is the view (product.blade.php):

    @foreach(App\Product::all() as $product)
        <div class="col-sm-6 col-md-4">
            <div class="thumbnail">
                <img src=  alt="...">
                <div class="caption">
                    <h3>  </h3>
                    <p class="discription">  </p>
                    <div class="clearfix">
                        <div class="pull-left price"/>$ </div>
                    <a href=  class="btn btn-danger pull-right" role="button">Add to cart</a>
                </div>
            </div>
        </div>
@endforeach



via Mette

Advertisement