/**
  * @return Collection
  */
 public function byLocale()
 {
     $collection = $this->groupBy('locale_id');
     $response = new Collection();
     $locales = app('Modules\\System\\Locale')->all();
     foreach ($locales as $locale) {
         $response->put($locale->slug, $collection->get($locale->id, new Collection()));
     }
     return $response;
 }
 /**
  * Gets meta data
  *
  * @param string $key
  * @param null|mixed $default
  * @param bool $raw
  * @return Collection
  */
 public function getMeta($key, $default = null, $raw = false)
 {
     $meta = $this->meta()->where('key', $key)->get();
     if ($raw) {
         $collection = $meta;
     } else {
         $collection = new Collection();
         foreach ($meta as $m) {
             $collection->put($m->id, $m->value);
         }
     }
     if (0 == $collection->count()) {
         return $default;
     }
     return $collection->count() <= 1 ? $collection->first() : $collection;
 }
 /**
  * Serialize intance's relations.
  *
  * @param \Illuminate\Support\Contracts\ArrayableInterface $instance
  * @return array
  */
 public function serializeRelations(ArrayableInterface $instance)
 {
     $result = new Collection();
     if (!$this->isCollection($instance)) {
         $collection = new Collection();
         $instance = $collection->add($instance);
     }
     $sub_result = $this->collectRelations($instance);
     $sub_result = $this->mergeRelations($sub_result);
     foreach ($sub_result as $id => $value) {
         $result->put($id, $value);
     }
     return $result->toArray();
 }