Do you extend
Eloquent
?
class Confirm extends Eloquent {
...
Can we see the database too?
Maybe this helps
$posts = Confirm::with('posts')->where('reply_user_id','=',Auth::user()->id)->get();
Thanks for the replies
these are my tables..
users: id name
post:id post user_id
reply:id reply post_id
confirm:id message reply_id post_id reply_user_id...
I'm trying to display all the posts by their post_id present in confirm table and that have reply_user_id=Auth::user()->id. Above query returns confirm object.Please provide me the solun. Thanks..
This is not the best solution as it will do multiple queries
$post_ids = Confirm::select('post_id')->where('reply_user_id','=',Auth::user()->id)->get()->toArray();
$post_ids = flatten($post_ids);
$posts = Post::whereIn('id',$post_ids);
function to flatten the array
function flatten(array $array) {
$return = array();
array_walk_recursive($array, function($a) use (&$return) { $return[] = $a; });
return $return;
}
OR
DB::table('confirm AS c')
->join('post AS p', 'c.post_id', '=', 'p.id')
->where('c.reply_user_id','=',Auth::user()->id)
->get();
hi,
I'm using this query
$post = DB::select('select p.post from post AS p,confirm AS c where p.id=c.post_id AND c.reply_user_id='.Auth::user()->id.'');
This worked for me.
Thank you.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community