本文整理汇总了PHP中Illuminate\Database\Eloquent\Model::toArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::toArray方法的具体用法?PHP Model::toArray怎么用?PHP Model::toArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Model
的用法示例。
在下文中一共展示了Model::toArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: toArray
public function toArray($user_id = null)
{
$array = parent::toArray();
$array['supporter_counter'] = (int) Redis::get('supporter_counter:' . $this->id);
$array['is_supported'] = (int) Redis::zscore('issue_supporters:' . $this->id, $user_id) > 0 ? 1 : 0;
return $array;
}
示例2: authorizeForResults
/**
* @param Model $model
* @param $column
* @return mixed
*/
protected function authorizeForResults(Model $model, $column)
{
if (!array_key_exists($column, $model->toArray())) {
return $this->authorize('add_activity', $model);
}
return $this->authorize('edit_activity', $model);
}
示例3: toArray
public function toArray()
{
$array = parent::toArray();
$array['user'] = $this->user;
$array['lista'] = $this->lista;
return $array;
}
示例4: __construct
public function __construct(\Illuminate\Database\Eloquent\Model $extra)
{
$this->common = $extra->toArray();
$this->composition = $extra->composition->toArray();
$this->atmosphere = $extra->atmosphere->toArray();
$this->orbit = $extra->orbit->toArray();
}
示例5: toArray
public function toArray()
{
$array = parent::toArray();
$array['opened_issue_counter'] = (int) Redis::get('user_opened_issue_counter:' . $this->id);
$array['supported_issue_counter'] = (int) Redis::get('user_supported_issue_counter:' . $this->id);
return $array;
}
示例6: saving
public function saving(Model $model)
{
$validator = Validator::make($model->toArray(), ['parent_id' => 'integer', 'name' => 'required']);
if ($validator->fails()) {
throw new \RuntimeException('Validate Fails');
}
}
示例7: toArray
public function toArray()
{
$data = parent::toArray();
if (!empty($data['photos'])) {
$data['photos'] = $this->processPhotos($data['photos']);
}
$data['age'] = false;
if (!empty($data['bdate'])) {
$bdate = explode('.', $data['bdate']);
if (count($bdate) >= 3) {
$bdate = new \DateTime($bdate[2] . '-' . $bdate[1] . '-' . $bdate[0]);
$now = new \DateTime();
$diff = $now->diff($bdate);
$year = $diff->y;
$age = trans_choice('main.age', $year, [], 'message', 'ru');
$data['age'] = $age;
}
}
if ($data['age'] == false) {
$year = rand(18, 25);
$age = trans_choice('main.age', $year, [], 'message', 'ru');
$data['age'] = $age;
}
return $data;
}
示例8: toArray
public function toArray()
{
$data = parent::toArray();
$data['sizes'] = $this->sizeURLs();
$data['url'] = $this->URL('m');
return $data;
}
示例9: toArray
public function toArray()
{
$array = parent::toArray();
$array['permission_role'] = $this->permission_role;
$array['user_detail'] = $this->user;
$array['role_detail'] = $this->roles;
return $array;
}
示例10: toArray
public function toArray()
{
$array = parent::toArray();
$text = json_decode($this->text, true);
$array['text'] = $text['message'];
$array['log_data'] = $text['data'];
return $array;
}
示例11: toArray
public function toArray($options = 0)
{
//return parent::toArray();
if ($options === 'default') {
return parent::toArray();
}
return $this->toArrayCamel();
}
示例12: toArray
/**
* Convert the model instance to an array.
*
* @return array
*/
public function toArray()
{
$data = parent::toArray();
if (isset($data['date']) && $data['date']) {
$data['date'] = $this->date->format('Y-m-d');
}
return $data;
}
示例13: getData
/**
* Retrieve data to validate.
*
* @author Morten Rugaard <moru@nodes.dk>
*
* @return array
*/
public function getData()
{
// If a model has been set, it'll take priority
if (!empty($this->model)) {
return $this->model->toArray();
}
return $this->data;
}
示例14: formatEloquentModel
/**
* Format an Eloquent model.
*
* @param \Illuminate\Database\Eloquent\Model $model
*
* @return string
*/
public function formatEloquentModel($model)
{
$key = str_singular($model->getTable());
if (!$model::$snakeAttributes) {
$key = camel_case($key);
}
return $this->encode([$key => $model->toArray()]);
}
示例15: toArray
public function toArray($outputAttributes = null)
{
$attributes = parent::toArray();
if (is_array($outputAttributes)) {
$attributes = array_intersect_key($attributes, array_flip($outputAttributes));
}
return $attributes;
}