JOHNMAC's avatar

product detail page is not showing

hi m trying to get product details by clicking on product at product listing page, when I click on product link then at next page URL is fine http://127.0.0.1:8000/product/2 but product is not showing

controller:

    public function productdetail(Request $request, Product $product)
    {
         return view('product.detail', compact('product'));
    }

route:

  Route::get('/product/{product}','Admin\ProductController@productdetail')->name('product.productdetail');

detail.blade.php

     <form method="POST" action="{{ route('product.productdetail', $product->id) }}" enctype="multipart/form-data">
     @csrf

          {{ $product->product_name }}

     </form>

at listening page m using this link for detail page:

      <a href="{{ route('product.productdetail', $product->id) }}" class="block2-name dis-block s-text3 p-b-5">

          {{ $product->product_name }}

      </a>
0 likes
5 replies
Snapey's avatar

You already used product/2 for your category route ?

JOHNMAC's avatar

maybe the problem is in routes because at both pages the url is same,

   // Product Listing Page
   Route::get('/product/{category}','Admin\ProductController@products')->name('product.products');

   // Product Detail Page
  Route::get('/product/{product}','Admin\ProductController@productdetail')->name('product.productdetail');
Snapey's avatar

as I said yesterday...

you need to use a new route for your category. Maybe productcategory/{category} or just category

you cannot have identical routes

1 like
JOHNMAC's avatar
JOHNMAC
OP
Best Answer
Level 2

I use this and now its working fine:

  Route::get('/product/{product}/details','Admin\ProductController@productdetail')->name('product.productdetail');
Snapey's avatar

how come you came up with the best answer?

Please or to participate in this conversation.