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

artisticre's avatar

Can't find table

This is the error I am getting

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'cursillo.user_user' doesn't exist

User Relationship

public function roles(){
        return $this->belongsToMany('App\Models\User');
    }

Role Relationship

public function users(){
        return $this->belongsToMany('App\Models\Role');
    }

UserController

public function update(Request $request, User $user)
    {
        $user->roles()->sync($request->roles);
        toastr()->success('User Role Has Been Updated');
        return redirect()->route('admin.users.index');
    }
0 likes
2 replies
tykus's avatar
tykus
Best Answer
Level 104

The relationship are not defined correctly, so Eloquent infers an incorrect table name. Just fix the relationship definitions

// Role
public function users()
{
    return $this->belongsToMany('App\Models\User');
}
// User
public function roles()
{
    return $this->belongsToMany('App\Models\Role');
}

Please or to participate in this conversation.