How to drop table in Laravel?

You can use drop or dropIfExists methods:

Schema::drop('users');

Schema::dropIfExists('users');

You can also rollback if you want to drop your last migrated table

php artisan migrate:rollback

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

php artisan migrate:reset

The migrate:fresh command will drop all tables from the database and then execute the migrate command:

php artisan migrate:fresh

php artisan migrate:fresh --seed

To drop a table, you may use the Schema::drop method:

Schema::drop('users');

// Better
Schema::dropIfExists('users');

You need a down method on your migration so that when you run php artisan migrate:rollback it can drop your database.

e.g.

<?php

use Illuminate\Database\Schema\Blueprint; 
use Illuminate\Database\Migrations\Migration; 

class CreateSongsTable extends Migration 
{ 
    public function up() 
    { 
        Schema::create('songs', function (Blueprint $table) { 
            $table->increments('id'); 
            $table->integer('user_id'); 
            $table->string('title'); 
            $table->string('slug')->unique(); 
            $table->timestamps(); 
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); 
        }); 
    }

    public function down()
    {
        Schema::drop('songs');
    }
}

To drop a table in laravel, Create a first migration

Step to drop a table

$ php artisan make:migration drop_user_table

Add this to your migrate file inside up function Schema::drop('tableName');

public function up() 
{
    Schema::dropIfExists(table('songs'));
    $table->increments('id');
    ...

}

then run

$ php artisan migrate

Tags:

Laravel 5