Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select rows that have columns equal values in laravel 5.2

I'm new user of Laravel 5.2

For example i have data rows something like this:

mytable
-------------------------------
url          |  ip         
-------------------------------
google.com   |  11.44.180.149       <----- 
msn.com      |  11.44.180.149 
google.com   |  11.44.180.149       <-----  
yahoo.com    |  11.44.180.149         
google.com   |  11.44.180.149       <----- 

I want select all rows that 2 or 3 columns value their is equal and delete rows equal that it's more than one

For example convert to this:

mytable
-------------------------------
url          |  ip         
-------------------------------
google.com   |  11.44.180.149       <----- 
msn.com      |  11.44.180.149 
yahoo.com    |  11.44.180.149    

Guys i'm so sorry because can't speak English very well.

Thank you

like image 676
Rai Rz Avatar asked Dec 28 '25 18:12

Rai Rz


1 Answers

You can use groupBy() method with Eloquent:

MyTable::groupBy('ip')->get();

Or query builder:

DB::table('mytable')->groupBy('ip')->get();
like image 193
Alexey Mezenin Avatar answered Dec 30 '25 08:12

Alexey Mezenin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!