Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

258
Views
Laravel fijó la fecha en 1970 cuando el valor es nulo

A veces, laravel establece la fecha 1970 cuando el valor es nulo, ¿es posible guardar el valor como NULL en lugar de 01-01-1970?

 'start_date' => date('Ym-d', strtotime($request->input('start_date'))), 'end_date' => $request->has('end_date') ? date('Ym-d', strtotime($request->input('end_date'))) : NULL,

Este código no funciona.

¿Cómo puedo solucionarlo?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

En MySQL, si el formato de fecha no está completo o no es válido, se establece en el valor predeterminado.

Actualice su función de fecha para incluir la hora, si tiene un campo de fecha y hora, también debe pasar una hora.

date("Ymd H:i:s");

 'start_date' => date('Ymd H:i:s', strtotime($request->input('start_date'))), 'end_date' => $request->has('end_date') ? date('Ymd H:i:s', strtotime($request->input('end_date'))) : NULL,
over 4 years ago · Santiago Trujillo Report

0

Según esta respuesta en Laravel 5.5+

  • $request->exists : Alias para $request->has

  • $request->has : determina si la solicitud contiene una clave de elemento de entrada determinada.

  • $request->filled : determine si la solicitud contiene un valor no vacío para un elemento de entrada.

Todo lo que necesita: el cambio has filled :

 'end_date' => $request->filled('end_date') ? date('Ymd H:i:s', strtotime($request->input('end_date'))) : NULL,
over 4 years ago · Santiago Trujillo Report

0

Por favor, intente el siguiente código

Necesita verificar si la solicitud está disponible y luego convertirla a tiempo

'start_date' =>$request->has('start_date') ? date('Ym-d', strtotime($request->input('start_date'))) : NULL,

'fecha_final' => $solicitud->has('fecha_final') ? date('Ym-d', strtotime($request->input('end_date'))) : NULL,

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!