Created
February 23, 2022 08:52
-
-
Save asilbalaban/81e5f583d97b893c722df4e61767398b to your computer and use it in GitHub Desktop.
remove duplicate unique column rows in laravel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| Route::get('test', function () { | |
| $raw = \DB::raw('count(*) as total'); | |
| $requestCounts = \App\Models\Cards::query()->select('card_slug', $raw)->havingRaw('COUNT(*) > 1')->groupBy('card_slug')->limit(500)->pluck('total', 'card_slug'); | |
| if (ob_get_level() == 0) ob_start(); | |
| foreach ($requestCounts as $key => $val) { | |
| echo $key . ' - ' . $val . '<br>'; | |
| $ids = \App\Models\Cards::where('card_slug', $key)->pluck('id'); | |
| unset($ids[0]); | |
| \App\Models\Cards::whereIn('id', $ids)->delete(); | |
| ob_flush(); | |
| flush(); | |
| echo '<script>var scrollingElement = (document.scrollingElement || document.body); | |
| scrollingElement.scrollTop = scrollingElement.scrollHeight;</script>'; | |
| } | |
| ob_end_flush(); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment