mirror of
https://github.com/flarum/core.git
synced 2025-10-10 14:34:30 +02:00
API: allow date attributes to be added
This commit is contained in:
@@ -47,7 +47,6 @@ class Discussion extends Model
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dates = ['start_time', 'last_time'];
|
||||
|
||||
/**
|
||||
* An array of posts that have been added during this request.
|
||||
@@ -62,6 +61,7 @@ class Discussion extends Model
|
||||
* @var \Flarum\Core\Models\Post[]
|
||||
*/
|
||||
public $removedPosts = [];
|
||||
protected static $dates = ['start_time', 'last_time'];
|
||||
|
||||
/**
|
||||
* The user for which the state relationship should be loaded.
|
||||
|
@@ -17,19 +17,26 @@ use LogicException;
|
||||
*
|
||||
* @todo Refactor out validation, either into a trait or into a dependency.
|
||||
* The following requirements need to be fulfilled:
|
||||
* - Ability for extensions to alter ruleset.
|
||||
* - Ability for extensions to alter ruleset (add, modify, remove).
|
||||
* - Ability for extensions to add custom rules to the validator instance.
|
||||
* - Use Flarum's translator with the validator instance.
|
||||
*/
|
||||
abstract class Model extends Eloquent
|
||||
{
|
||||
/**
|
||||
* Indicates if the model should be timestamped. Turn them off by default.
|
||||
* Indicates if the model should be timestamped. Turn off by default.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* The attributes that should be mutated to dates.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $dates = [];
|
||||
|
||||
/**
|
||||
* The validation rules for this model.
|
||||
*
|
||||
@@ -162,6 +169,26 @@ abstract class Model extends Eloquent
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attributes that should be converted to dates.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDates()
|
||||
{
|
||||
return static::$dates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an attribute to be converted to a date.
|
||||
*
|
||||
* @param string $attribute
|
||||
*/
|
||||
public static function addDate($attribute)
|
||||
{
|
||||
static::$dates[] = $attribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an attribute from the model. If nothing is found, attempt to load
|
||||
* a custom relation method with this key.
|
||||
|
Reference in New Issue
Block a user