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

dextersiah1998's avatar

Pull data with inner join

I have 3 Tables Here project_users, projects,users. Both projects and users primary key are stored in projects_users as foreign key to keep track of which user belongs to which project as (1 project can have many users). I'm trying to pull the data from project_user and doing a inner join to project where the "type" in project's column is "team". I have tried following the laravel documentation of join but im getting an error

SQLSTATE[42S02]: Base table or view not found: 1051 Unknown table 'manageme.projects_users' (SQL: select projects_users., projects. from project_users inner join projects on project_users.p_id = projects.p_id where projects.type = team)

Here are more information

ProjectUser Model

public function projects(){
    return $this->belongsTo('App\Project','p_id');
}

public function users(){
    return $this->belongsTo('App\User','u_id');
}       

ProjectUser Table

- pu_id
- p_id
- u_id

Projects Table

- p_id
- p_name
- start_date
- end_date
- status
- type

My Eloquent Query

$teamProject = DB::table('project_users')
                        ->join('projects','project_users.p_id','=','projects.p_id')
                        ->select('projects_users.*','projects.*')
                        ->where('projects.type','=','team')
                        ->get();
0 likes
2 replies
adamprickett's avatar
Level 6

In your select() method on line 3 of the query, you refer to the non-existent table projects_users - just change for project_users

Please or to participate in this conversation.