Hi,
Today, i we will show you laravel 8 delete all records from table example. This article will give you simple example of laravel 8 delete all records from table example. you will learn laravel 8 delete all records from table example. So let’s follow few step to create example of laravel 8 delete all records from table example.
Example 1:
<?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(); } }
Example 2:
<?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::whereNotNull('id')->delete(); } }
Example 3:
<?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:where('id', 'like' '%%')->delete(); } }
Example 4:
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use DB; class UserController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { DB::table('users')->delete(); } }
I hope it will assist you…