I am learning model relationships in Laravel. I am having the following issue:
I have a table for 'NPIData' with primary key as NPI
I have a table for 'Users' with primary key as id
I have a table for 'UserToProviderMapping' with two columns, one for user_id (maps to id on users table) and one for provider_npi (maps to NPI on NPIData table).
I have the following code in my controller:
public function index()
{
//
$user = Auth::id();
$providers = UserToProviderMapping::where('user_id', $user)->get();
return view ('my-health-hub', compact('providers'));
}
I have the following code in my view currently (obviously incomplete)
@foreach($providers as $provider)
<li>{{$provider->provider_npi}}</li>
@endforeach
I am not sure if I can use a model relationship here because I have added another table in between the two models (users and NPIData). I am trying to get the provider_npi from the UserToProviderMapping table and use that to look up the data within the NPIData table and loop through.