Quantcast
Channel: User Mohamed Mufeed - Stack Overflow
Viewing all articles
Browse latest Browse all 36

Answer by Mohamed Mufeed for Adding additional column to the result of relationship in eloquent

$
0
0

You can do

$companyUsers = CompanyUserProduct::with('companyUser:id,user_id')->get();

To retrieve the CompanyUserProduct along with the id and user_id of compantUser.

Note: whatever your primary key for companyUser - make sure you select it as well. (In this case assumed to be id)

Once you retrieve the collection, the user_id will be under companyUser for each CompanyUserProduct

So, you can pluck it using dot notation.

eg:

$userIds = $companyUsers->pluck('companyUser.user_id');

Viewing all articles
Browse latest Browse all 36

Trending Articles