Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

You can break off from a query and continue it as you please.

$funs_query = DB::table('funs')
        ->select(array('funs.*', 'user_votes.like_vote', 'user_votes.dislike_vote', 'user_votes.user_id'))
        ->leftjoin('user_votes', 'user_votes.fun_id', '=', 'funs.id')
        ->where('funs.visible', '=', '1');

if (Auth::check()) {
    $funs_query->where('user_votes.user_id', '=', Auth::user()->id);
}

$funs_result = $funs_query->orderBy('funs.created_at', 'desc')
        ->groupby('funs.id')
        ->take(3)->get();
Last updated 2 years ago.
0

Thanks for reply:) i solved my problem with this query

	$funs_query = DB::table('funs')
		->select(array('funs.*', 'user_votes.like_vote', 'user_votes.dislike_vote', 'user_votes.user_id'))
		->leftjoin('user_votes', function($join){
			$join->on('user_votes.fun_id', '=', 'funs.id')
				->where('user_votes.user_id', '=', Auth::user()->id);
		})				
		->where('funs.visible', '=', '1')
		->orderBy('funs.created_at', 'desc')
		->groupby('funs.id')
		->take(3)->get();
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Ditmens ditmens Joined 23 Sep 2014

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.