As discussed in the comments, this is a SQL limitation - you cannot use an alias for a column in a where
clause.
One workaround, as suggested by @ljubadr, is to use having
instead - although I will side with @Jeffrey on this and say it is going to unnecessarily make your query slower.
Rather than use the alias, you can utilise whereRaw()
:
$tabla_c2 = DB::table('horarios')
->select('id_voluntario',DB::raw("DATE_FORMAT(fecha,'%y-%m-%d')as fechas"))
->where('id_voluntario','=', $temp)
->whereRaw("DATE_FORMAT(fecha,'%y-%m-%d') = ?", $datee)
->get();
See the docs under Eloquent Aggregates
.