In your select() method on line 3 of the query, you refer to the non-existent table projects_users - just change for project_users
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. fromproject_usersinner joinprojectsonproject_users.p_id=projects.p_idwhereprojects.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();
Please or to participate in this conversation.