jeudi 18 juillet 2019

Retrieve single value by id from many to many relationship

I am trying to get a single value (company) from a list of companies that belong to a user with id=x. So far I can get the whole list of companies, but I want to get the single one by its ID.

Thank you very much!

with this I cant get all the companies.

$user = auth('api')->user();

$companies = $user->company;

I tried many things, the last one was

    $companies = $user->company->where('id', $id);

but I got

"message": "Undefined variable: company",



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire