Search code examples
phplaravellaravel-routing

Why I am getting wrong URI?


I am currently on

http://127.0.0.1:8000/cars/

I have a link that has to route me to

http://127.0.0.1:8000/cars/create

I used this in my code

            <a
                href="cars/create"
            </a>

In my web.php I have following route

Route::get('cars/create',function ()
{
    return view('carsops.create');
});

When I click on link I am redirected to

http://127.0.0.1:8000/cars/cars/create

Instead of

http://127.0.0.1:8000/cars/create

What is the error why I am getting this extra /cars. Can some one help me.


Solution

  • You have to put a / in front of the link:

            <a
                href="/cars/create"
            </a>
    

    This means Go to the site root, then got to cars path then go to the create path.