Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent
Last updated 1 year ago.
0

IMHO.... The better solution would be to discover how duplicate rows are being added and prevent it from happening.

Do you know how they get there? You could add database constraints to prevent it but I'm not sure how the application layer will respond. If you can find in the application where they get added you should be able to prevent it.

But to address your question directly.... you can get the count of rows, then delete them with a limit 1 less the count

$row_count = Article::where('url', '=', $url)->count()
DB:delete('delete from article where url = ? limit ?', array($url, ($row_count - 1)))
Last updated 1 year ago.
0

If you just need to clean up your records, you might consider just running a query directly... This looks like a really good way to do it, I believe I've tried it before:

ALTER IGNORE TABLE jobs ADD UNIQUE INDEX idx_name (site_id, title, company );

http://stackoverflow.com/questions/3311903/remove-duplicate-ro...

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

aligajani aligajani Joined 29 May 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.