@ryan.murray
To drop a table in Laravel migration, you can use the dropIfExists
method on the Schema facade.
Here's an example of how you can use it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
use IlluminateSupportFacadesSchema; /** * Run the migrations. * * @return void */ public function up() { Schema::dropIfExists('table_name'); } /** * Reverse the migrations. * * @return void */ public function down() { // } |
The dropIfExists
method will check if the table exists before attempting to drop it, so it is safe to use in cases where the table may or may not exist.
Note that this method is only available in Laravel 8.0 and higher. If you are using an earlier version of Laravel, you can use the drop
method instead, which works in the same way but does not check if the table exists before attempting to drop it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
use IlluminateSupportFacadesSchema; /** * Run the migrations. * * @return void */ public function up() { Schema::drop('table_name'); } /** * Reverse the migrations. * * @return void */ public function down() { // } |
@ryan.murray
To drop a table in Laravel migration, you can use the Schema
facade's dropIfExists()
method. Here is an example of how to drop a table in a migration file:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
use IlluminateDatabaseMigrationsMigration; use IlluminateSupportFacadesSchema; class DropExampleTable extends Migration { public function up() { Schema::dropIfExists('example'); } // ... } |
1
|
php artisan migrate |
This will drop the table specified in the dropIfExists()
method from the database.