本文整理汇总了PHP中Eloquent::toArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Eloquent::toArray方法的具体用法?PHP Eloquent::toArray怎么用?PHP Eloquent::toArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Eloquent
的用法示例。
在下文中一共展示了Eloquent::toArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: toArray
public function toArray()
{
$results = parent::toArray();
$results['translated'] = $this->translated();
// $results['image_dynamic'] = $this->image_dynamic;
return $results;
}
示例2: toArray
public function toArray()
{
$array = parent::toArray();
if (isset($this->variance)) {
$array['variance'] = $this->variance->toArray();
}
return $array;
}
示例3: toArray
/**
* Convert the model instance to an array.
*
* @return array
*/
public function toArray()
{
$data = parent::toArray();
$data['id'] = (int) $data['id'];
$data['completed'] = $this->completed;
$data['created_at'] = $this->fromDateTime($this->created_at);
$data['updated_at'] = $this->fromDateTime($this->updated_at);
return $data;
}
示例4: toArray
public function toArray()
{
$array = parent::toArray();
if (!isset($this->visiblePivotAttributes)) {
return $array;
}
foreach ($this->visiblePivotAttributes as $relationship => $attributes) {
$array[$relationship] = $this->fetchRelationshipPivotAttributes($relationship, $attributes);
}
return $array;
}
示例5: toArrayFechas
public function toArrayFechas()
{
$array = parent::toArray();
$esquema = $this->getEsquema();
foreach ($esquema as $col) {
if (strtolower(substr($col->Type, 0, 4)) == 'date') {
$array[$col->Field] = date('d/m/Y', strtotime($this->{$col->Field}));
}
}
return $array;
}
示例6: toArray
public function toArray()
{
$array = parent::toArray();
$clean = array();
foreach ($array as $attr => $value) {
if ($attr === 'url') {
$clean[$attr] = $value;
continue;
}
$clean[$attr] = is_numeric($value) ? (int) $value : $value;
}
return $clean;
}
示例7: toArray
public function toArray(User $user = null)
{
$arr = parent::toArray();
$arr['read'] = false;
if (!isset($user)) {
unset($arr['user_statuses']);
return $arr;
}
foreach ($arr['user_statuses'] as $status) {
if ($status['user_id'] == $user->id && $status['status'] == 'read') {
$arr['read'] = true;
}
}
unset($arr['user_statuses']);
return $arr;
}
示例8: toArray
public function toArray()
{
$array = parent::toArray();
// return $array;
if ($this->type == Asset::ASSET_TYPE_IMAGE) {
$array['url'] = URL::to($this->url());
$array['base_url'] = URL::to($this->resizeImageURL());
$array['extension'] = $this->getExtension();
} else {
if ($this->type == Asset::ASSET_TYPE_AUDIO) {
$array['url'] = URL::to($this->getRelativeURL());
}
}
$array['files'] = File::files($this->getRelativePath());
return $array;
}
示例9: toChangesArray
public function toChangesArray(TimesheetEvent $other)
{
$attributes_old = parent::toArray();
$attributes_new = $other->toArray();
$skip_keys = ['id' => 1, 'created_at' => 1, 'updated_at' => 1, 'deleted_at' => 1, 'org_data' => 1, 'update_data' => 1];
$zeroisempty_keys = ['discount' => 1];
$result = [];
// Find all the values that where changed or deleted
foreach ($attributes_old as $key => $value) {
// Skip null values, keys we don't care about and 0 value keys that means they are not used
if (empty($value) || isset($skip_keys[$key]) || isset($zeroisempty_keys[$key]) && $value) {
continue;
}
// Compare values if it exists in the new array
if (isset($attributes_new[$key]) || array_key_exists($key, $attributes_new)) {
if ($value instanceof \DateTime && $attributes_new[$key] instanceof \DateTime) {
if ($value != $attributes_new[$key]) {
$result[$key] = $attributes_new[$key]->format("Y-m-d H:i:s");
}
} elseif ($value instanceof \DateTime && is_string($attributes_new[$key])) {
if ($value->format("Y-m-d H:i:s") != $attributes_new[$key]) {
$result[$key] = $attributes_new[$key];
}
} elseif (is_string($value) && $attributes_new[$key] instanceof \DateTime) {
if ($attributes_new[$key]->format("Y-m-d H:i:s") != $value) {
$result[$key] = $attributes_new[$key]->format("Y-m-d H:i:s");
}
} elseif ($value != $attributes_new[$key]) {
$result[$key] = $attributes_new[$key];
}
} else {
$result[$key] = null;
}
}
// Find all the values that where deleted
foreach ($attributes_new as $key => $value) {
if (isset($skip_keys[$key])) {
continue;
}
if (!isset($attributes_old[$key])) {
$result[$key] = $value;
}
}
return $result;
}
示例10: getValues
/**
* Gets the picked values for the entered fields
*
* @param array $fields
* @param Eloquent $model
* @return array
*/
protected function getValues($fields, $model, $page)
{
$values = array_except($model->toArray(), ['id', 'created_at', 'updated_at', 'deleted_at']);
foreach ($fields as $field) {
foreach ($field->picks as $modelAttribute => $fieldAttribute) {
$values[$modelAttribute] = $field->values->get($fieldAttribute, null);
}
}
if ($this->Schema->hasColumn($model->getTable(), 'page_version_id')) {
$values['page_version_id'] = $page['page_version_id'];
}
if ($this->Schema->hasColumn($model->getTable(), 'language_id')) {
$values['language_id'] = $page['language_id'];
}
return $values;
}
示例11: toArray
public function toArray()
{
$array = parent::toArray();
// small modifications
$array['unixtime'] = strtotime($array['created_at']);
$array['edited'] = strtotime($array['updated_at']);
$array['timeago'] = time_ago($array['created_at']);
$array['time'] = modding_link(rtrim($array['time']));
$array['text'] = linkify(modding_link($array['text']));
$array['icon'] = $array['is_resolved'] ? $this->icons['resolved'] : (@$this->icons[$array['type']] ?: '');
// renames
$array['id'] = $array['item_id'];
$array['beatmap'] = $array['beatmap_id'];
$array['resolved'] = $array['is_resolved'];
// unsets
unset($array['item_id']);
unset($array['beatmapset_id']);
unset($array['beatmap_id']);
unset($array['is_resolved']);
unset($array['created_at']);
unset($array['updated_at']);
if (!$array['deleted_at']) {
unset($array['deleted_at']);
}
return $array;
}
示例12: toArray
/**
* Include link to annotation when converted to array
*
* @param null
* @return parent::toArray()
*/
public function toArray()
{
$this->link = $this->getLink();
return parent::toArray();
}
示例13: toArray
public function toArray()
{
$array = parent::toArray();
// small modifications
$array["unixtime"] = strtotime($array["created_at"]);
$array["edited"] = strtotime($array["updated_at"]);
$array["timeago"] = time_ago($array["created_at"]);
$array["time"] = modding_link(rtrim($array["time"]));
$array["text"] = linkify(modding_link($array["text"]));
$array["icon"] = $array["is_resolved"] ? $this->icons["resolved"] : (@$this->icons[$array["type"]] ?: "");
// renames
$array["id"] = $array["item_id"];
$array["beatmap"] = $array["beatmap_id"];
$array["resolved"] = $array["is_resolved"];
// unsets
unset($array["item_id"]);
unset($array["beatmapset_id"]);
unset($array["beatmap_id"]);
unset($array["is_resolved"]);
unset($array["created_at"]);
unset($array["updated_at"]);
if (!$array["deleted_at"]) {
unset($array["deleted_at"]);
}
return $array;
}
示例14: toArray
public function toArray()
{
$array = parent::toArray();
$array['url'] = URL::to('/spots/tags/' . $this->slug);
return $array;
}
示例15: toArray
public function toArray()
{
$array = parent::toArray();
$array['existsPaid'] = $this->existsPaid;
$array['tokenExists'] = $this->tokenExists;
return $array;
}