Whitney W. Whitney W. - 1 year ago 84
PHP Question

Use delete glyphicon in Laravel 5 to delete a data

Hi need help in glyphicons with delete functionality.
These are my icons for update and delete. However, I only have my update working. I do not do with my delete. Please help! THanks a lot!

<a href='{{ url("admin/editTicket/$ticket->id") }}'><span class="glyphicon glyphicon-pencil"></span></a>
<a href="#"><span class="glyphicon glyphicon-trash"></span></a>

Controller codes for update ticket:
where Chap_ticket is my database table name

public function editTicket($id)
$tick = Chap_ticket::find($id);
return view('admin.registerTicket',compact('tick','tickets'));


My Route:

Route::get('admin/deleteTicket', 'AdminController@deleteTicket');

Answer Source

You need to create a new controller action like e.g. below:

public function deleteTicket($id) { 
    $tick = Chap_ticket::find($id);
    return Redirect::back()->with('msg', 'Ticket deleted'); 

You may need to associate the new action with a route so you can add the following in your routes:

Route::get('admin/deleteTicket/{id}', 'Admin\AdminController@deleteTicket');

Assuming your controller is called AdminController

And in your view:

@if (isset($msg))

<a href='{{ url("admin/editTicket/$ticket->id") }}'><span class="glyphicon glyphicon-pencil"></span></a>
<a href="{{ url("admin/deleteTicket/$ticket->id") }}"><span class="glyphicon glyphicon-trash"></span></a>

This is based on the assumption that your view is a general admin page which will still be valid to when the ticket is deleted.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download