binggle
1 year ago
1537
5
Eloquent

how to use 'with()' in Laravel DB Query Builder ?

Posted 1 year ago by binggle

In this case I gave up to use ORM Eloquent .

SO I decided to use DB Query builder only.

But I want to drag 'user' model with my 'results' model .

How can I get success ?

    $bettings = DB::table('results')
            ->select('1st', '2nd', DB::raw('SUM(time_laps) as time_laps'))
            ->where('event_id', $event_id)
            ->join('type', function( $join) use( $type) {
                $join->on('results.type_id', '=', 'type.id')
                        ->where('types.key' , '=', $type) ;
            })
            ->groupBy('1st', '2nd')
            ->with('user')
            ->get();


            ->with('user')

I guess I can not use with() in Query Builder.

Actually I wish I can build ORM Eloquent query than DB Query Builder .

If it's not possible I want to drag user model with results model .

Can someone help me ?

Please sign in or create an account to participate in this conversation.