示例#1
0
/**
 * Transform Eloquent models to a JSON object.
 *
 * @param  Eloquent|array  $models
 * @return object
 */
function to_array($models)
{
    if ($models instanceof Laravel\Database\Eloquent) {
        return $models->to_array();
    }
    return array_map(function ($m) {
        return $m->to_array();
    }, $models);
}
 public function to_array()
 {
     $data = parent::to_array();
     foreach ($data as $k => &$v) {
         if (in_array($k, array('id', 'outer_wall', 'inner_wall', 'decking', 'global', 'per_block', 'sort_order'))) {
             $v = (int) $v;
         }
     }
     return $data;
 }
/**
 * Transform Eloquent models to a JSON object.
 *
 * @param  Eloquent|array  $models
 * @return object
 */
function eloquent_to_json($models)
{
    if ($models instanceof Laravel\Database\Eloquent\Model) {
        return json_encode($models->to_array());
    }
    return json_encode(array_map(function ($m) {
        return $m->to_array();
    }, $models));
}
示例#4
0
 function to_array()
 {
     $array = array('created_at' => $this->asTimestamp(), 'updated_at' => $this->asTimestamp('updated_at'));
     $array += parent::to_array();
     static::$hasURL and $array += array('url' => $this->url());
     return $array;
 }