Home>

I want to get a collection when many-to-many relations are multiple in Laravel.
I created a DB and model with the following structure,
I don't know how to get the list of projects that the user has from Auth :: id ().
(Finally, pass it in the form of return view ('hoge', [projects' =>$projects]) and turn it with foreach in view.)
(It has been confirmed that if there is only one intermediate table, it can be acquired normally. (Acquiring a project list of company, etc.))

users table

id name password email

user_company table

id user_id company_id

companies table

id name url overview

company_project table

id company_id project_id

projects table

id name overview cost

Due to trial and error, various errors and problems have occurred, but
I couldn't think of a way to make the type relationship work,
I also think there is a better way to get all the columns without getting them every time.

Supplementary information (FW/tool version, etc.)

Laravel 6.x
MySQL
Please do not hesitate to tell us if there is a lack of information.