For getting every new tutorial link Please join our telegram group

Part 5 laravel eloquent how to work delete() vs truncate() method with hindi video

In this laravel tutorial we will discuss data delete and destroy. delete method remove a single row data and truncate method remove all table data

Laravel delete vs truncate method

Laravel delete method remove one row at a time by delete method where as truncate method use for empty the table. truncate method delete all rows from related model and delete method only delete one by one row but not reset autoincrement column data where as truncate method reset autoincrement column also. Let see example of delete and truncate method

Example of delete method
<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Student;

class StudentController extends Controller{
 public function index(){
    $id = 7;
    $student = Student::find($id);

    $student->delete();
  }

}
Example of truncate method
<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Student;

class StudentController extends Controller{
 public function index(){
    $student = Student::truncate();
  }

}

You read this tutorial on advanced web tutorial. here we provide laravel beginners to advanced laravel tutorial.

php laravel developer anmol sharma

Anmol Sharma

I am a software engineer and have experience in web development technologies like php, Laravel, Codeigniter, javascript, jquery, bootstrap and I like to share my deep knowledge by these blogs.

Related tutorial links