Ok, this is messed up. You have a post
table with a id_user
. Then you have a user
table with id_user
. AND THEN you ALSO have a post_user
table to connect the two again? That makes no sense in my opinion.
What do you want to achieve with your query? I think it needs a rethink.
Other option: look at http://laravel.com/docs/4.2/queries#advanced-wheres and lose the 'post_user' in the second orWhere()
(Just a guess)
I know what is wrong.
This part of code inside your function.
where('post.id_post', '=', 'post_user.id_post')
This will result in a query that contains
post.id_post = 'post_user.id_post'
id_post is a integer, but you pass a string into the where. The third parameter of a where() must not be a column name to compare to, but the value to comepare to.
Instead, use a whereRaw().
whereRaw('post.id_post = post_user.id_post')
Ok, sorry for the mess. The goal of this query is to publish the posts that have been posted by you that you visit the profile: ->join('user', 'post.id_user', '=', 'user.id_user') ->where('user.id_user', '=', $id_user)
or those published by another user on the user whose profile you are visiting the page: ->orWhere('post.id_amico', '=', $id_user)
or those shared by this user: ->orWhere(function($query) use ($id_user) { $query->where('post', 'post_user.id_post', '=', 'post.id_post') ->where('post_user.id_user', '=', $id_user); })
and that is where the problems begin, because I can not specify the use of the table "post_user" which is what I need. There is the possibility of using two tables in orWhere function ()? That's what I want to understand.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community