
Chcę skorzystać z przykładu nospora

Ale nie wiem jak dodać zapytanie w laravelu

Kombinowałem w ten deseń, ale nie działa
$results = DB::select("SELECT @idnr AS nr FROM (SELECT @nr:=@nr +1, IF( ID=@id, @idnr:=@nr ,@idnr=@idnr), ID FROM `users` ORDER BY respect DESC) podsel WHERE podsel.ID = @id", ['@id' => Auth::user()->id, '@nr'=> 0, '@idnr' => 0 ]); return $results;
A i tak próbowałem
DB::statement('set @id=10, @nr = 0, @idnr = 0'); $orders = DB::select( DB::raw("select @idnr as nr from (SELECT @nr:=@nr+1,if(ID=@id, @idnr := @nr,@idnr=@idnr),ID FROM users ORDER BY respect DESC) podsel where podsel.ID = @id") ); return $orders;
OK, zwracana odpowiedź musi wyglądac tak:
DB::statement(DB::raw('set @id=10, @nr = 0, @idnr = 0') ); $orders = DB::select(DB::raw("select @idnr as nr from (SELECT @nr:=@nr+1,if(ID=@id, @idnr := @nr,@idnr=@idnr),ID FROM users ORDER BY respect DESC) podsel where podsel.ID = @id") ); return $orders[0];
i wtedy w blade {{ $orders->nr }}
Pozdrawiam.