Create Todo app with laravel – Update and Delete


Hello World, Welcome to my laravel tutorial series Learn Laravel with example. This is second part of create todo app with laravel. In the previous article, we have learned that how to add and show data with laravel and MySQL. In this article we will extend the previous article. We will perform update and delete operation with laravel in this article.

I have divided this tutorial in the following parts.

Update the Controller File

  • Open TodoController.php  Controller in text editor that you have created in last tutorial and add the following code in it for update and delete.
// Edit Todo
    function edit($id){
    	return view('update',['todo'=>$data]);

    // Update Todo
    function update(Request $request,$id){
        return redirect('todo/edit/'.$id)->with('success', 'Task has been updated!');
    // Delete Todo Task
    function delete($id){
        DB::table('todos')->where('id', $id)->delete();
        return redirect('/')->with('success', 'Task has been deleted!');

Create the View Files

  • Create the edit.blade.php file at the same place where add.blade.php has been created and add the following code.
@section('title', 'Update Task')
<h2 class="mb-3">Update Task</h2>

<table class="table table-bordered">
	<form action="{{url('todo/update')}}/{{$todo->id}}" method="POST">
	{{ csrf_field() }}
		<tr class="bg-success">
			<td colspan="2">
			<th colspan="4"><a href="{{url('/')}}" class="btn btn-secondary btn-sm"><< Task List</a></th>
			<td><input type="text" value="{{ $todo->title }}" class="form-control" name="title" /></td>
				<textarea name="desc" class="form-control" rows="10">{{ $todo->description }}</textarea>
			<td colspan="2">
				<input type="submit" class="btn btn-danger" />

Update the Route file

  • Open the web.php in routes folder and update with the following code.


Open the todo url in the browser. Now you can perform edit and delete operation in this todo app.

You can download full source code from this link.

Leave a Reply