prgrm
prgrm

Reputation: 3833

Need to compare two rows from the DB in Laravel

I have the table users in laravel.

A user has, among other things, an id and an owner_id.

I want to perform a query to get all the owners. That means, where the id is equal to owner_id.

Users::where('id','owner_id')->get();

Something like this. This didn't work obviously.

Any suggestions?

Upvotes: 0

Views: 912

Answers (1)

Don't Panic
Don't Panic

Reputation: 41810

Use whereColumn instead.

Users::whereColumn('id','owner_id')->get();

With where, obviously you're just looking for a literal string 'owner_id'.

Upvotes: 2

Related Questions