title: 404 on add to cart laravel
body: <p>i have this situation on add to cart when i want to add to cart i am getting 404 error,</p>
  <p>this is my route</p>
  <pre><code>Route::get('/add-to-cart/{product}', [CartController::class, 'addToCart'])-&gt;name('add.cart');
  Route::get('/remove/{id}', [CartController::class, 'removeFromCart'])-&gt;name('remove.cart');
  Route::get('/change-qty/{product}', [CartController::class, 'changeQty'])-&gt;name('change_qty');
  </code></pre>
  <p>This is controller
  namespace App\Http\Controllers;</p>
  <pre><code>use Illuminate\Http\Request;
  
  use App\Models\Products;
  
  class CartController extends Controller
  {
  /**
   * Display a listing of the resource.
   *
   * @return \Illuminate\Http\Response
   */
  public function index()
  {
      //
      return view('cart.index');
  }
  
  public function addToCart(Products $product)
  {
      $cart = session()-&gt;get('cart');
      if (!$cart) {
          $cart = [$product-&gt;id =&gt; $this-&gt;sessionData($product)];
          return $this-&gt;setSessionAndReturnResponse($cart);
      }
      if (isset($cart[$product-&gt;id])) {
          $cart[$product-&gt;id]['quantity']++;
          return $this-&gt;setSessionAndReturnResponse($cart);
      }
      $cart[$product-&gt;id] = $this-&gt;sessionData($product);
      return $this-&gt;setSessionAndReturnResponse($cart);
  
  }
  
  public function changeQty(Request $request, Products $product)
  {
      $cart = session()-&gt;get('cart');
      if ($request-&gt;change_to === 'down') {
          if (isset($cart[$product-&gt;id])) {
              if ($cart[$product-&gt;id]['quantity'] &gt; 1) {
                  $cart[$product-&gt;id]['quantity']--;
                  return $this-&gt;setSessionAndReturnResponse($cart);
              } else {
                  return $this-&gt;removeFromCart($product-&gt;id);
              }
          }
      } else {
          if (isset($cart[$product-&gt;id])) {
              $cart[$product-&gt;id]['quantity']++;
              return $this-&gt;setSessionAndReturnResponse($cart);
          }
      }
  
      return back();
  }
  
  public function removeFromCart($id)
  {
      $cart = session()-&gt;get('cart');
  
      if (isset($cart[$id])) {
          unset($cart[$id]);
          session()-&gt;put('cart', $cart);
      }
      return redirect()-&gt;back()-&gt;with('success', &quot;Removed from Cart&quot;);
  }
  
  protected function sessionData(Products $product)
  {
      return [
          'name' =&gt; $product-&gt;nume,
          'quantity' =&gt; 1,
          'price' =&gt; $product-&gt;pret,
      ];
  }
  
  protected function setSessionAndReturnResponse($cart)
  {
      session()-&gt;put('cart', $cart);
      return redirect()-&gt;route('cart')-&gt;with('success', &quot;Added to Cart&quot;);
  }
  </code></pre>
  <p>This is what i have in view file:</p>
  <pre><code>&lt;a class=&quot;theme_btn add_cart w-100&quot; href=&quot;{{route('add.cart', [$produs-&gt;id])}}&quot;&gt;add to cart
       &lt;span class=&quot;theme_btn_eff&quot;&gt;&lt;/span&gt;
  &lt;/a&gt;
  </code></pre>
  <p>In my loop when i fetch products, on click is redirecting me to 404 page without getting an error, i was trying to get dd($product) into controller but i get again 404.</p>