davy_yg's avatar
Level 27

wishlist

When clicking the wishlist button I get this error:

(1/1) NotFoundHttpException

I wonder why?

store/index.blade.php

<a href="{{ url('/wishlist/add/'. $product->prod_id ) }}" class="button-wishlist">Wishlist</a>

WishlistsController.php

public function add(Products $product)
    {
    Wishlists::create([
      'prod_id' => $product->prod_id,
      'user_id' => auth()->user()->user_id
    ]);

    flash('Product added to wishlist.');

    return back();
    }

web.php

Route::get('/wishlists/add/{product}', 'WishlistsController@add');
0 likes
4 replies
bobbybouwmann's avatar
Level 88

You url in your view is singular (wishlist) and the route is plurar (wishlists). This should work

<a href="{{ url('/wishlists/add/'. $product->prod_id ) }}" class="button-wishlist">Wishlist</a>

In general it's better to name your routes and use the name in your view. This way you won't mix up urls ;)

Documentation: https://laravel.com/docs/5.8/routing#named-routes

Snapey's avatar

and use php artisan route:list to check what your routes are called

davy_yg's avatar
Level 27

I cannot call php artisan

D:\xampp72\htdocs\lekaeshop>php artisan route:list  
Could not open input file: artisan
Snapey's avatar

Why do you not have artisan in your project?

Please or to participate in this conversation.