Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sonichandni/6c3d217f9168a35a0d014a297017d417 to your computer and use it in GitHub Desktop.
Save sonichandni/6c3d217f9168a35a0d014a297017d417 to your computer and use it in GitHub Desktop.
Route::get('/clear-user-data', function() {
Schema::disableForeignKeyConstraints();
$tables = DB::select('SHOW TABLES');
// echo "<pre>"; print_r($tables); exit;
// $cnt = 93;
$cnt = range(55,89);
// $cnt = range(87,91);
foreach($cnt as $c){
foreach($tables as $table){
if($table != 'users'){
if (Schema::hasColumn($table->Tables_in_dbName, 'user_id')) {
$row = DB::table($table->Tables_in_dbName)->where('user_id', $c)->delete();
// if($row){
// $row->delete();
// }
}
}
}
DB::table('users')->where('id', $c)->delete();
}
Schema::enableForeignKeyConstraints();
return 'cleared';
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment