Good night,
In this code, i got an error that says that the variable userId doesn't exists when its called inside the subquery (whereIn).
If i call it before the return line, i got it's value.
public static function despesasFamiliares ( $periodoDe, $periodoAte, $userId ) {
return $despesas = \DB::table('despesas')
->select('despesas.id', 'despesas.descricao', 'despesas.valor', 'despesas.data', 'despesas_categoria.descricao AS categoriaDescricao', 'despesas_origem.descricao AS origemDescricao' , 'users.username AS usersNome')
->join('despesas_categoria', 'despesas_categoria.id', '=', 'despesas.despesas_categoria_id')
->join('despesas_origem', 'despesas_origem.id', '=', 'despesas.despesas_origem_id')
->join('users', 'users.id', '=', 'despesas.users_id')
->whereIn('users_id', function($query)
{
$query->select('users_id')
->from('users_share_despesas')
->where('allowed_users_id', '=', $userId);
})
->where('data', '>=', $periodoDe)
->where('data', '<=', $periodoAte)
->where('despesas.deleted_at', '=', null)
->orderBy('data')
->get();
}
This could be a bug? Or there is some write error???
Thank you all
you have missed the use
keyword
->whereIn('users_id', function($query) use( $userId )
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community