Reputation: 81
i have a question to my db query.
My DB tables/schema:
i try to get all Projects where a user has access through customers to, with the following query:
//call
User::find(Auth::id())->first()->projects();
//User.model
public function projects() {
return User::with('customers.projects')->get();
}
It works. But now i have User data, Customer data and Project Data in the result array. I want only the Projects. Is there an other way?
Upvotes: 3
Views: 168
Reputation: 220066
$user = auth()->user()->load('customers.projects');
$projects = $user->customers->pluck('projects')->collapse()->unique();
Upvotes: 0