Welcome To ITSolutionsGuides,
Lets see How To Delete All Records From Table In Laravel Using Truncate() using it solutions guides tutorial. To delete all the records from the table we will use the truncate() to delete all the table records. Laravel offer truncate() to delete all the records from the table. This example is supported in all versions of the laravel. During the testing of the laravel applications we will add lot of dummy records using Factory tinker when during the launching of the application we need to delete all the dummy records. To delete all the records from the table using laravel Eloquent which provides truncate() method for deleting all the records.
To clear all records from a Laravel table, use the truncate method on the model associated with the table. This efficiently removes all rows, resetting auto-incremented IDs
In this example we will delete all the records in the users table using the truncate()
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
class UserController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
User::truncate();
}
}
We hope it helps everyone. Thanks for supporting ITSolutionsGuides and keep supporting us also follow us in social media platforms.
Be the first to know about releases and tutorial news and solutions.
We care about your data in our privacy policy.
ITSolutionsGuides was started mainly to provide good and quality web solutions for all the developers. We provide tutorials to support all the developers and also we try to provide solutions to the errors we face while coding.
Copyright © 2023 - 2024 All rights reserved | ITSolutionsGuides