Im using an achor to click a button to navigate to other page. However, it doesnt work and return a 404 error not found.
inventory.blade.php:
<a class="d-xl-flex align-items-xl-center" href="{{ url('inventory/add')}}" style="padding-right: 0px;margin-right: 15px;"><button class="btn btn-primary d-xl-flex align-items-xl-center" type="button" style="margin-right: -16px;margin-bottom: 13px;margin-top: 7px;border-color: rgb(162,138,138);background: rgb(0,0,0);padding-bottom: 0px;padding-top: 1px;margin-left: -26px;">ADD PRODUCT</button></a>
controller: NavBar.php:
public function inv(){
return view('inventory');
}
public function invadd(){
return view('inventory-add');
}
I tried moving the inv() in another controller page and it’s not already viewable or accessible by the routing. Is it because of referencing thing? I think my controller cannot access the blades in the resources/views folder.
5
Answers
I'm using my old code with url and it worked. I just prompt this in terminal:
You have an anchor tag surronding a button, which doesn’t make sense. use either one or the other. That said, you can –
Give your routes a name
Then link to it by using the route helper.
You also seem to be trying POST to a route using an anchor tag, which also doesn’t make sense. You probably want a form with a submit button which will sent the data using POST with the data from the form.
try again, like this:
As per your comment:
Controller method
and in your blade
You are trying to open a link that is assigned to a
post
route, that’s why you’re getting 404 error, common oversight actually.Have you tried putting a slash in the front like this:
For example you are currently on the location:
And you have this
Clicking on that link, you will go to:
So you really have to put a slash character in front of
inventory
so that you will go toRegardless of your current location on your project.