Skip to content
Advertisement

Laravel Users follow

I have this error

SQLSTATE[23000]: Integrity constraint violation: 1052 Column ‘id’ in field list is ambiguous (SQL: select id, followers.user_id as pivot_user_id, followers.follows_id as pivot_follows_id, followers.created_at as pivot_created_at, followers.updated_at as pivot_updated_at from users inner join followers on users.id = followers.follows_id where followers.user_id = 1 and follows_id = 2 limit 1)

(View: /Users/harshitsingh/Documents/logos/resources/views/users/index.blade.php) and this is my UsersController

JavaScript

I am trying user to user relationship this is User Model `

JavaScript

`

Advertisement

Answer

Try to learn how to read the error message.

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in field list is ambiguous

This message tells you that there’s 2 or more id field, which SQL doesn’t know which one to SELECT. From your UserController code, the code doesn’t seem to be in there, chances are you need to look at your User model.

You will have to update

SELECT id ...

to

SELECT users.id ...

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement