Add DateTime support to database binding layer.
Signed-off-by: Taylor Otwell <taylorotwell@gmail.com>
This commit is contained in:
@@ -193,7 +193,7 @@ abstract class Model {
|
||||
{
|
||||
$model = new static(array(), true);
|
||||
|
||||
if (static::$timestamps) $attributes['updated_at'] = $model->get_timestamp();
|
||||
if (static::$timestamps) $attributes['updated_at'] = new \DateTime;
|
||||
|
||||
return $model->query()->where($model->key(), '=', $id)->update($attributes);
|
||||
}
|
||||
@@ -405,21 +405,11 @@ abstract class Model {
|
||||
*/
|
||||
protected function timestamp()
|
||||
{
|
||||
$this->updated_at = static::get_timestamp();
|
||||
$this->updated_at = new \DateTime;
|
||||
|
||||
if ( ! $this->exists) $this->created_at = $this->updated_at;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current timestamp in its storable form.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get_timestamp()
|
||||
{
|
||||
return date('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a new fluent query builder instance for the model.
|
||||
*
|
||||
|
||||
@@ -204,7 +204,7 @@ class Has_Many_And_Belongs_To extends Relationship {
|
||||
{
|
||||
if (Pivot::$timestamps)
|
||||
{
|
||||
$attributes['created_at'] = $this->model->get_timestamp();
|
||||
$attributes['created_at'] = new \DateTime;
|
||||
|
||||
$attributes['updated_at'] = $attributes['created_at'];
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ class Has_One_Or_Many extends Relationship {
|
||||
{
|
||||
if ($this->model->timestamps())
|
||||
{
|
||||
$attributes['updated_at'] = $this->model->get_timestamp();
|
||||
$attributes['updated_at'] = new \DateTime;
|
||||
}
|
||||
|
||||
return $this->table->update($attributes);
|
||||
|
||||
Reference in New Issue
Block a user