You need to use this for setting sql variable:
DB::statement(DB::raw('set @sum=0'));
Then goes your query (more or less raw).
Example usage:
public function scopeWithRowNumber($query, $column = 'created_at', $order = 'asc')
{
DB::statement(DB::raw('set @row=0'));
$sub = static::selectRaw('*, @row:=@row+1 as row')
->orderBy($column, $order)->toSql();
$query->from(DB::raw("({$sub}) as sub"));
}
thanks jarektkaczyk,
separating it to a standalone statement is what I needed
DB::statement(DB::raw('set @row=0'));
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community