Reputation: 145
I have a task to delete button in my laravel application.
This is My blade file delete button,
<a href="/projects/{{ $project->id }}/tasks/{{ $task->id }}/delete" class="editInline"><i class="glyphicon glyphicon-trash"></i></a>
and TaskController delete method,
public function deleteOneProjectTask($projectId, $taskId)
{
DB::table('tasks')
->where('project_id', $projectId)
->where('id', $taskId)
->delete();
return redirect()->route('projects.show')->with('info', 'Task deleted successfully');
}
and task delete routes,
Route::delete('projects/{projects}/tasks/{tasks}/delete', [
'uses' => '\App\Http\Controllers\TasksController@deleteOneProjectTask',
]);
now I need a confirm alert massage before the delete a task when click delete button. how can I develop it?
Upvotes: 1
Views: 284
Reputation: 16436
Simple add onclick
event on anchor tag.
<a href="/projects/{{ $project->id }}/tasks/{{ $task->id }}/delete" class="editInline" onclick="return confirm('Are you sure to want to delete this record?')"><i class="glyphicon glyphicon-trash"></i></a>
Example:
<a href="/projects/{{ $project->id }}/tasks/{{ $task->id }}/delete" class="editInline" onclick="return confirm('Are you sure to want to delete this record?')">DELETE</a>
If user Click on ok
then only your href
action will be execute.
Upvotes: 5