toArray() публичный Метод

Convert the model instance to an array.
public toArray ( ) : array
Результат array
Пример #1
0
 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;
 }
 /**
  * @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
0
 public function toArray()
 {
     $array = parent::toArray();
     $array['user'] = $this->user;
     $array['lista'] = $this->lista;
     return $array;
 }
Пример #4
0
 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
0
 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
0
 public function saving(Model $model)
 {
     $validator = Validator::make($model->toArray(), ['parent_id' => 'integer', 'name' => 'required']);
     if ($validator->fails()) {
         throw new \RuntimeException('Validate Fails');
     }
 }
Пример #7
0
 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
0
 public function toArray()
 {
     $data = parent::toArray();
     $data['sizes'] = $this->sizeURLs();
     $data['url'] = $this->URL('m');
     return $data;
 }
Пример #9
0
 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
0
 public function toArray()
 {
     $array = parent::toArray();
     $text = json_decode($this->text, true);
     $array['text'] = $text['message'];
     $array['log_data'] = $text['data'];
     return $array;
 }
Пример #11
0
 public function toArray($options = 0)
 {
     //return parent::toArray();
     if ($options === 'default') {
         return parent::toArray();
     }
     return $this->toArrayCamel();
 }
Пример #12
0
 /**
  * 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
0
 /**
  * Retrieve data to validate.
  *
  * @author Morten Rugaard <*****@*****.**>
  *
  * @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
0
 /**
  * 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
0
 public function toArray($outputAttributes = null)
 {
     $attributes = parent::toArray();
     if (is_array($outputAttributes)) {
         $attributes = array_intersect_key($attributes, array_flip($outputAttributes));
     }
     return $attributes;
 }
Пример #16
0
 /**
  * Convert the model instance to an array.
  *
  * @return array
  */
 public function toArray()
 {
     $data = parent::toArray();
     if (isset($data['selection'])) {
         $data['activated'] = (bool) $data['selection'];
         unset($data['selection']);
     }
     return $data;
 }
Пример #17
0
 public function findPrevious(Model $model)
 {
     $key = $this->buildCacheKey(['findPrevious', $model->toArray()]);
     if ($records = $this->getFromCache($key)) {
         return $records;
     }
     $records = $this->repository->findPrevious($records);
     return $this->put($key, $records);
 }
Пример #18
0
 public function toArray()
 {
     $array = parent::toArray();
     if ($this->hasImages) {
         $this->loadImages();
     }
     $array['images'] = $this->images;
     return $array;
 }
Пример #19
0
 /**
  * Convert the model instance to an array.
  *
  * @return array
  */
 public function toArray()
 {
     // http://10.80.32.59/DARES3/public/
     $as = $this->urlsForAttachment('attachment');
     array_walk($as, function (&$a) {
         $a = asset($a);
     });
     // array_walk($as, function(&$a) {$a = asset($a);});
     return array_merge(parent::toArray(), ['attachment' => $as]);
 }
Пример #20
0
 public function toArray()
 {
     $result = parent::toArray();
     $result['category'] = $this->getCategory()->simpleAttributes();
     $result['tags'] = $this->tags()->get()->map(function ($x) {
         return $x->simpleAttributes();
     })->toArray();
     $result['user'] = $this->user()->first()->toArray();
     return $result;
 }
Пример #21
0
 public function toArray()
 {
     $array = parent::toArray();
     if (array_key_exists('email', $array)) {
         $array['email'] = $array['email']['email'];
     }
     if (array_key_exists('created_at', $array)) {
         $array['created_at'] = $this->created_at->timestamp * 1000;
     }
     return $array;
 }
Пример #22
0
 /**
  * If $attributes is given, will use the list only
  * @param attributes
  */
 public function toArray(array $attributes = array())
 {
     $data = parent::toArray();
     if (count($attributes) == 0) {
         return $data;
     }
     $new = array();
     foreach ($attributes as $attribute) {
         $new[$attribute] = $data[$attribute];
     }
     return $new;
 }
Пример #23
0
 /**
  * Notify user.
  *
  * @param  \Orchestra\Contracts\Notification\Recipient  $recipient
  * @param  \Illuminate\Database\Eloquent\Model  $user
  * @param  array  $changes
  * @param  array  $config
  *
  * @return bool
  */
 public function notify(Recipient $recipient, Model $user, array $changes, array $config = [])
 {
     if (!$this->mailer instanceof Notification) {
         throw new RuntimeException("Mailer need to be an instance of Orchestra\\Contracts\\Notification\\Notification.");
     }
     if (!!$this->unguarded || empty($changes)) {
         return false;
     }
     $data = ['user' => $user instanceof Arrayable ? $user->toArray() : $user, 'changes' => $changes];
     $message = Message::create($config['email'], $data);
     return $this->mailer->send($recipient, $message);
 }
Пример #24
0
 /**
  * Return the attributes in an array.
  * Here we convert DateTimes to ISO 8601 format.
  *
  * @return array
  */
 public function toArray()
 {
     $array = parent::toArray();
     foreach ($this->getDates() as $dateAttribute) {
         if (in_array($dateAttribute, $this->hidden)) {
             continue;
         }
         $value = $this->{$dateAttribute};
         if ($value) {
             $carbon = $this->asDateTime($this->{$dateAttribute});
             $array[$dateAttribute] = $carbon->format(\DateTime::ATOM);
         }
     }
     return $array;
 }
Пример #25
0
 public function toArray()
 {
     if (isset($this->nested) && count($this->nested)) {
         foreach ($this->nested as $attribute) {
             $this->hidden[] = "{$attribute}_id";
             $this->{$attribute};
         }
     }
     if ($this->dateformat) {
         $this->appends[] = 'created';
         $this->appends[] = 'updated';
         $this->hidden[] = 'created_at';
         $this->hidden[] = 'updated_at';
     }
     return parent::toArray();
 }
Пример #26
0
 public function toArray(array $properties = null)
 {
     if ($properties === null) {
         return parent::toArray();
     }
     $dates = $this->getDates();
     $array = [];
     foreach ($properties as $p) {
         if (in_array($p, $dates)) {
             $array[$p] = (string) $this->asDateTime($this->{$p});
         } else {
             $array[$p] = $this->{$p};
         }
     }
     return $array;
 }
Пример #27
0
 /**
  * Currently only used in the angular part, to return them through an /api/admin call.
  *
  *
  */
 public function toArray()
 {
     $result = parent::toArray();
     switch ($this->type->name) {
         case 'boolean':
             $result['value'] = (bool) $result['value'];
             break;
         case 'string':
             break;
         case 'text':
             break;
         case 'select':
             break;
         case 'numeric':
             break;
     }
     return $result;
 }
Пример #28
0
 public function toArray()
 {
     $data = parent::toArray();
     if ($data['media'] != null) {
         $largest = $data['media']['data'][0];
         $medias = $data['media']['data'];
         foreach ($medias as $media) {
             if ($media->width > $largest->width && $media->height > $largest->height) {
                 $largest = $media;
             }
         }
         $data['media']['data'] = [$largest];
         return $data;
     } else {
         unset($data['media']);
         return $data;
     }
 }
Пример #29
0
 public function transform(Model $model)
 {
     $attributes = $model->toArray();
     $allowedAclFields = $this->getAllowedAclFields($model);
     foreach ($attributes as $fieldName => $value) {
         if (!in_array($fieldName, $allowedAclFields)) {
             unset($attributes[$fieldName]);
         }
     }
     $attributes['meta'] = [];
     if (in_array('meta.*', $allowedAclFields)) {
         $attributes['meta'] = $model->meta;
     } else {
         $meta = $model->meta;
         foreach ($model->metaFields() as $key) {
             if (isset($meta[$key])) {
                 $attributes['meta'][$key] = $meta[$key];
             }
         }
     }
     return $attributes;
 }
 public function toArray()
 {
     return $this->reverseMatch($this->model->toArray());
 }