Home > OS >  Problem with opening a view, Error 404, Not Found
Problem with opening a view, Error 404, Not Found

Time:05-17

So... The Error might be obvious but I cant find it. Im using Laravel 9. The Error is '404 Not found'.

This is the Route

Route::get('/list', [ValidationController::class, 'index']);

This is the function inside the controller.(It is the correct Controller)

 public function index()
    {
        $data = Validation::all();
        return view('products.list', compact('data'));
    }

And this is the HTML to call this route

<div>
    <a href="/list">Products</a>
</div>

The File 'list' exists in the 'products' directory.

Thank you for your answers.. :)

My show function in a different Controller works just fine..

public function show(Product $product)
    {
        return view('products.show', compact('product'));
    }

CodePudding user response:

The path in your href attribute is most likely the issue. When creating a link, Laravel has a helper function to help out with routes: route(). The best practise is to name your route in your routes.php file:

Route::get('/list', [ValidationController::class, 'index'])->name('route.name');

When creating a link, you will be able to just do this:

<a href="{{ route('route.name') }}">Products</a>
  • Related