Rana Raheel Tariq
Rana Raheel Tariq

Reputation: 101

Controller Inheritance in Laravel 5.6

I have three Table users, Profiles, and Documents. I'm Create single user Profile page using relationship now i want to fetch data or Documents related to user profile. every Single user Have Many Documents. i don't know to fetch all Document related to user.

public function show(User $client)
{
    return view('admin.profile', compact('client'));
}

it's single profile fetch function.

Upvotes: 0

Views: 163

Answers (1)

Rwd
Rwd

Reputation: 35180

If you're happy to access them through your $client variable in your view file then you can simply do $client->document.

If you want to be a bit more explicit or you change this is be an ajax response then in your controller you would have:

$client->load('document');

Or if you want to load the relationship in to a different variable you can do:

$document = $client->document()->first();

return view('admin.profile', compact('client', 'document'));

Upvotes: 1

Related Questions