I'm using Laravel and I'm trying to achieve a delete function that takes care of deleting the selected task the user made.
I was wondering how can I achieve this using routes?
<a href="{{ route("tasks.edit", ["id" => $task->id]) }}"><button class="btn btn-outline-light">Edit</button></a>
<a href="{{ route("tasks.destroy", ["id" => $task->id]) }}"><button class="btn btn-outline-light">Delete</button></a>
At this moment my delete route takes me to the same page as what the edit route does.
My delete function:
public function destroy(Task $task)
{
$task->delete();
return redirect('/tasks')->with('success', 'Task removed');
}
I got a working delete function using the Laravel forms:
{!! Form::open(['action' => ['TasksController@destroy', $task->id], 'method' => 'POST', 'class'=> 'float-right']) !!}
{{Form::hidden('_method','DELETE')}}
{{Form::submit('Delete', ['class' => 'btn btn-outline-danger'])}}
{!! Form::close() !!}
Is it worth to consider another method of taking care of my deletes or should I stick with using the Laravel forms?