Laravel Drop all tables with MySQL

Today, We want to share with you Laravel Drop all tables with MySQL.In this post we will show you “Drop all tables” instead of “migration rollback”, hear for Laravel – Delete all records from table query we will give you demo and example for implement.In this post, we will learn about Drop tables, types and views using wipe artisan command in Laravel 6 with an example.

Laravel Drop all tables with MySQL

There are the Following The simple About laravel migration change column type Full Information With Example and source code.

As I will cover this Post with live Working example to develop laravel delete all relations, so the laravel truncate table with foreign key is used for this example is following below.

Delete all the tables in database in one shot

migrations when you can’t rollback.

foreach(\DB::select('SHOW TABLES') as $table) {
    $all_table_names = get_object_vars($table);
    \Schema::drop($all_table_names[key($all_table_names)]);
}

php artisan migrate:reset

The migrate:reset command will roll back all of your application’s migrations:

Artisan::call('migrate:reset', ['--force' => true]);

truncate all tables in laravel using eloquent

//Get all the table names
$all_table_names = Schema::getConnection()->getDoctrineSchemaManager()->listTableNames();

foreach ($all_table_names as $name) {
    //if you don't want to truncate migrations in Database
    if ($name == 'migrations') {
        continue;
    }
    DB::table($name)->truncate();
}

Laravel 6 Session More Details

  PHP Conditional Statements Example

Laravel – Delete all records from table query

Example 1:

User::truncate();

Example 2:

User::whereNotNull('id')->delete();

Example 3:

Product:where('id', 'like' '%%')->delete();

Example 4:

DB::table('products')->delete();

Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about laravel truncate table with foreign key.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Reply

avatar
  Subscribe  
Notify of