Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Laravel efficient way to remove X records if there are duplicates

protected function deleteDuplicateApplications($hash = '', $skip = 5)
{
    // First get total count
    $totalCount = Application::where('hash', $hash)->count();

    // Then skip certain amount and take rest and delete it.
    return Application::where('hash', $hash)
                        ->orderBy('created_at', 'desc')
                        ->skip($skip)
                        ->take($totalCount - $skip)
                        ->delete();
}
Comment

PREVIOUS NEXT
Code Example
Php :: php mysql foreach is bad pardics ? 
Php :: how to search locations in php using ajax google script 
Php :: most sites visited by ip address laravel 
Php :: overwrite existing key value pair php 
Php :: yajra add column 
Php :: laravel model relationships with two columns match 
Php :: how to upload images to sql database php PDO 
Php :: nodejs php 
Php :: route laravel 
Php :: spatie media library 
Php :: apache/2.4.52 (win64) openssl/1.1.1m php/8.1.2 server at localhost port 80 
Php :: create custom rule in laravel 
Php :: what should write for getting extension of image in php 
Php :: how to get the url parameter in blade laravel 
Php :: enable cors cakephp 
Php :: how to increment date in php 
Php :: wpdb count 
Php :: setup PDO 
Java :: dependency for spring security 
Java :: java enum get nex 
Java :: spring enable debug log level 
Java :: javafx button color 
Java :: storage permission android 
Java :: Card view implement 
Java :: how to validate email java 
Java :: how to set the text of a jlabel to bold 
Java :: array to map java1 
Java :: sieve of eratosthenes java 
Java :: how to implement linked list in java without using collection framework 
Java :: how to install java 11 jdk on ubuntu 20.04 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =