truncate all tables in laravel using eloquent

前端 未结 6 577
别跟我提以往
别跟我提以往 2021-02-05 02:52

Is there a way I could truncate all the tables in a db using eloquent or fluent in laravel 4? I do not want to specify table names, I just want to truncate all the tables. In ot

6条回答
  •  天涯浪人
    2021-02-05 03:46

    Use this:

    $tables = DB::select('SHOW TABLES');
    // it do truncate all tables in database
       foreach($tables as $table){
          if ($table == 'migrations') {
              continue;
          }
          DB::table($table->Tables_in_portal_test)->truncate();
    }
    

    Remember you import

    use Illuminate\Support\Facades\DB;

    PD: Tables_in_YOUR_DATABASE_NAME

提交回复
热议问题