Lumen: How to delete a record from DB?
<p>Using Lumen, I'm displaying "Tickets". Here's my <code>Tickets.blade.php</code>:</p>

<pre><code>@foreach($tickets as $ticket)
&lt;div&gt;
    &lt;p&gt;{{ $ticket-&gt;id }}&lt;/p&gt;
    &lt;p&gt;{{ $ticket-&gt;content }}&lt;/p&gt;
    &lt;button onclick="deleteTicket({{$ticket-&gt;id}})"&gt;Delete&lt;/button&gt;
&lt;/div&gt;
@endforeach
</code></pre>

<p>So essentially, each time someone clicks delete, it triggers this script:</p>

<pre><code>&lt;script&gt;
    function deleteTicket(id) {
        jQuery.ajax({
            type: "post",
            url: "/tickets/deleteTicket",
            data: id,
            dataType: "text",
            success: function () {
                console.log('deleted!');
            }
        });

    }
&lt;/script&gt;
</code></pre>

<p>In my <code>routes.php</code>, I have this:</p>

<pre><code>$app-&gt;post('tickets/deleteTicket','TicketsController@deleteTicket');
</code></pre>

<p>Finally, in my <code>TicketsController.php</code>, I have:</p>

<pre><code>public function deleteTicket($id) {
    $ticket = Ticket::find($id);
    $ticket-&gt;delete();

    return redirect('/tickets');
}
</code></pre>

<p>The problem I'm getting when I press the button (console):</p>

<blockquote>
  <p>POST <a href="http://example.com/tickets/deleteTicket" rel="nofollow">http://example.com/tickets/deleteTicket</a> 404 (Not Found)</p>
</blockquote>

<p>I don't understand what I'm doing wrong, and why that method isn't being found. Can anyone help out?</p>

<p><strong>EDIT-</strong> I have changed my <code>routes.php</code> to:</p>

<pre><code>$app-&gt;get('tickets/deleteTicket/{id}','TicketsController@deleteTicket');
</code></pre>

<p>My script looks the same but I changed the "type" to <code>get</code> rather than <code>post</code>.</p>

<p>If I visit, this site: <code>http://mysite/tickets/deleteTicket/1</code>, the ticket will be deleted, and it redirects to <code>tickets</code> page. But if the button is clicked, this error happens:</p>

<blockquote>
  <p><a href="http://MYSITE/tickets/deleteTicket?id=3" rel="nofollow">http://MYSITE/tickets/deleteTicket?id=3</a> 404 (Not Found)</p>
</blockquote>

<p>At this point, I'm thinking that I just need to revise my AJAX call to the correct URL, but I want to make sure security is an issue.</p>