问题
I have this query, I would like to obtain only the data created on the current month
public function index(Request $request)
{
if($request->ajax())
{
$data = DB::table('tbl_lista_contactabilidad as a')
->select('a.id','a.rif','a.razon_social','a.postventaatcs_id','fecha_contacto','a.contactado','a.persona_contacto','a.correo_contacto','a.celular_contacto','a.numero_contacto','a.comentarios','a.auditado')
->leftjoin('tbl_equipo_postventaatcs as h','h.id','=','a.postventaatc_id')
->leftjoin('users as l','l.id','=','h.asesor_id')
->leftjoin('tbl_lista_respuestas as b','b.id','=','a.auditado')
->leftjoin('tbl_lista_respuestasc as c','c.id','=','a.contactado')
->where('l.idop', auth()->user()->idop)
->where('a.estatus','=',1)
->select(array('a.id','l.name as idop_asesor','l.apellido as ape_asesor','l.idop','a.rif','a.razon_social','a.estatus','fecha_contacto','a.contactado', 'a.persona_contacto','a.correo_contacto','a.celular_contacto','a.numero_contacto','a.comentarios','a.auditado','b.respuesta','c.respuestac'));
}
return view('contactabilidadasesor');
}
回答1:
I am not sure if your query is correct, probably one of the two select() should be removed.
Although, in order to fetch the data created on the current month add in your query the following
->whereYear('a.created_at', Carbon::now()->year)
->whereMonth('a.created_at', Carbon::now()->month)
来源:https://stackoverflow.com/questions/60642036/how-to-filt-data-by-time-using-laravel