CodeIgniter Laravel PHP Example Javascript jQuery MORE

How to delete data from database using Laravel framework

In this example we will discuss about how to delete a record or data from MySQL database using laravel framework PHP.

The DELETE statement is used to delete records from a table:

DELETE FROM table_name
WHERE some_column = some_value

Notice : The WHERE clause specifies which record or records that should be deleted. If you omit the WHERE clause, all records will be deleted!

To learn more about SQL, please visit our SQL tutorial.

Create 3 file for delete data

  • StudDeleteController.php (app/Http/Controllers/StudDeleteController.php)
  • stud_delete_view.blade.php (resources/views/stud_delete_view.blade.php)
  • web.php (routes/web.php)

The following examples delete the record with id=3 in the "users" table:

To delete a record from table you must have insert data.If you want to know how to insert data in laravel framework please visit : Insert data in Laravel.

The students table look like this:

id first name last name City name Email Id Action
1 Divyasundar Sahu Mumbai Delete
2 Hritika Sahu Pune Delete
3 Milan Jena Chennai Delete

Now i am going to delete the id=3 record.

For delete record we use 3 file here


<!DOCTPE html>
<title>View Student Records</title>
<table border = "1">
<td>First Name</td>
<td>Last Name</td>
<td>City Name</td>
@foreach ($users as $user)
<td>{{ $user->id }}</td>
<td>{{ $user->first_name }}</td>
<td>{{ $user->last_name }}</td>
<td>{{ $user->city_name }}</td>
<td>{{ $user->email }}</td>
<td><a href = 'delete/{{ $user->id }}'>Delete</a></td>


namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class StudDeleteController extends Controller {
public function index(){
$users = DB::select('select * from student_details');
return view('stud_delete_view',['users'=>$users]);
public function destroy($id) {
DB::delete('delete from student_details where id = ?',[$id]);
echo "Record deleted successfully.
echo 'Click Here to go back.';


/* |--------------------------------------------------------------------------
| Web Routes
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
//delete data

After delete the record the table look like this.

id first name last name City name Email Id Action
1 Divyasundar Sahu Mumbai Delete
2 Hritika Sahu Pune Delete