Have you read docs on request, and looked at the php manual on request types and how they work.
Hitting POST routes with link.
So I'm looking for some advice on whether this is a good idea or not. I have come across a few situation when building apps where I want to trigger a route via a link, but I want want to use a something other than a GET request. A good example of this would be logging a user out. I could do this with a GET, but I would prefer to use POST or DELETE as to avoid any chance the user could bookmark the link. So I came up with a solution. I created a small javascript function.
function sendAsPost(action)
{
var form = $('#sendAsPostForm');
form.attr('action', action);
form.submit();
}
Then I add a form to my main layout so it's on every page.
<form action="" method="POST" id="sendAsPostForm">
{!! csrf_field() !!}
</form>
Now I can call a POST route with a link from anywhere in my app as simple as this:
<a href="#" onclick="sendAsPost(' route('logout') ')">Log-out</a>
--for some reason it removes the blade syntax curly braces around the route--
This seems to work great, I was just wondering how other people have dealt with this? Or if this is a terrible idea for some reason I'm not seeing. Thanks!
Please or to participate in this conversation.