php - How to make my own timestamp method in Laravel? -


typically, laravel platform have $table->timestamps(); in migration..., generate 2 datetime fields, implement own timestamps or, maybe call unix_timestamps(). have 2 fields named created_at, , updated_at, , store unix timestamps, how can implement it? thanks.

you don't have use laravel's timestamp helpers, convenient. there ways of working string timestamps too, including php's datetime class. digress, use unix timestamps...

  1. in schema (migration), use

    $table->integer('created_at'); $table->integer('updated_at'); 

    instead of

    $table->timestamps(); 
  2. replace timestamp() function in models.

  3. keep $timestamps = true in models.

here's example base model use, , extend instead of eloquent on models:

// models/basemodel.php class basemodel extends eloquent {      /**      * indicates if model has update , creation timestamps.      *      * @var bool      */     public static $timestamps = true;      /**      * set update , creation timestamps on model.      */     public function timestamp()     {         $this->updated_at = time();          if ( ! $this->exists) $this->created_at = $this->updated_at;     } }  // models/thing.php class thing extends basemodel {  } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -