Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 1 year ago.
0

Do you extend Eloquent?

class Confirm extends Eloquent {
...
Last updated 1 year ago.
0

Can we see the database too?

Maybe this helps

$posts = Confirm::with('posts')->where('reply_user_id','=',Auth::user()->id)->get();
Last updated 1 year ago.
0

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..

Last updated 1 year ago.
0

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();
Last updated 1 year ago.
0

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.

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.