Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

adhik13th's avatar

How to connect foreign-key on 3 tables relation

I dont know how to create a great title , iam sorry . so i have 3 table . USER , SPECIAL_USER, EDUCATION_SPECIAL_USER

in USER i have data basic like

id ,name , address , email ,etc

in SPECIAL_USER data

id , user_id , height , weight

in EDUCATION_SPECIAL_USER i have

id , special_user_id , name_school , skills , etc

i have table LIKE on this table . i have problem how to call EDUCATION_SPECIAL_USER based on id on USER . its have problem because my EDUCATION_SPECIAL_USER is not have relation directly on USER table . its my controller , how to solve this

  public function PDF_profile(Request $request,$id){
   $users = User::findOrFail($id);
   $special_users= Special_Users::where('user_id',$id)->first();
   $EDUCATION_SPECIAL_USER= EDUCATION_SPECIAL_USER::where('Special_User_id',$id)->get();
   
    $pdf = PDF::loadView('admin.pdf_profile',
    [
    'EDUCATION_SPECIAL_USER '=>$EDUCATION_SPECIAL_USER ,
    'users' => $users,
    'special_users'=> $special_users,
   

    
    ]);
    dd($r_kgb);
     //return $pdf->stream('Profile.pdf')->header('Content-Type','application/pdf'); 
                 
}

this data is not out because this wrong id , how i can solve this ?

0 likes
2 replies
bekaskaki's avatar

use first()

EDUCATION_SPECIAL_USER::where('user_id',$id)->first();

adhik13th's avatar

why first ? i want to show all data on this id

Please or to participate in this conversation.