3

En la documentación de las migraciones en Laravel 5.7 indica:

$table->timestamps();
// Adds nullable created_at and  updated_at TIMESTAMP equivalent columns.

$table->nullableTimestamps();
// Alias of timestamps() method.

Por lo que supongo que no hay diferencia entre usar uno y otro y el segundo habrá quedado de versiones antiguas por compatibilidad o algún otro motivo.

1
  • es un alias y es lo mismo... cual es la pregunta exacta? el 2 feb. 2019 a las 12:10

1 respuesta 1

0

Revisando el código de Laravel, vemos que no hay ninguna diferencia, nullableTimestamps() llama a timestamps() con los mismos parámetros de entrada, sin embargo yo utilizo timestamps(), es más cortos y es una instrucción menos de código (aunque sabemos que esto es despreciable en términos de tiempo).

/**
 * Add nullable creation and update timestamps to the table.
 *
 * @param  int  $precision
 * @return void
 */
public function timestamps($precision = 0)
{
    $this->timestamp('created_at', $precision)->nullable();

    $this->timestamp('updated_at', $precision)->nullable();
}

/**
 * Add nullable creation and update timestamps to the table.
 *
 * Alias for self::timestamps().
 *
 * @param  int  $precision
 * @return void
 */
public function nullableTimestamps($precision = 0)
{
    $this->timestamps($precision);
}

Para más información del código, revisa: https://github.com/laravel/framework/blob/5.7/src/Illuminate/Database/Schema/Blueprint.php#L953


Respondiendo a si existía alguna diferencia en versiones anteriores, la respuesta es sí, en Laravel 5.1 nullableTimestamps() creaba campos que permitían valores null, mientras timestamps(), no:

/**
 * Add nullable creation and update timestamps to the table.
 *
 * @return void
 */
public function nullableTimestamps()
{
    $this->timestamp('created_at')->nullable();
    $this->timestamp('updated_at')->nullable();
}
/**
 * Add creation and update timestamps to the table.
 *
 * @return void
 */
public function timestamps()
{
    $this->timestamp('created_at');
    $this->timestamp('updated_at');
}

Para más información de este código de Laravel 5.1: https://github.com/laravel/framework/blob/5.1/src/Illuminate/Database/Schema/Blueprint.php#L775

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.