/**
  * Pulls an item from the collection.
  *
  * @param  mixed  $key
  * @param  mixed  $default
  * @return mixed
  */
 public function pull($key, $default = null)
 {
     return Arr::pull($this->items, $key, $default);
 }
 /**
  * Get a MessageBag instance from the bags.
  *
  * @param  string  $key
  * @return \Illuminate\Contracts\Support\MessageBag
  */
 public function getBag($key)
 {
     return Arr::get($this->bags, $key) ?: new MessageBag();
 }
Example #3
0
 /**
  * Get an item from an array or object using "dot" notation.
  *
  * @param  mixed   $target
  * @param  string|array  $key
  * @param  mixed   $default
  * @return mixed
  */
 function data_get($target, $key, $default = null)
 {
     if (is_null($key)) {
         return $target;
     }
     $key = is_array($key) ? $key : explode('.', $key);
     while (($segment = array_shift($key)) !== null) {
         if ($segment === '*') {
             if (!is_array($target) && !$target instanceof ArrayAccess) {
                 return value($default);
             }
             $result = Arr::pluck($target, $key);
             return in_array('*', $key) ? Arr::collapse($result) : $result;
         }
         if (is_array($target)) {
             if (!array_key_exists($segment, $target)) {
                 return value($default);
             }
             $target = $target[$segment];
         } elseif ($target instanceof ArrayAccess) {
             if (!isset($target[$segment])) {
                 return value($default);
             }
             $target = $target[$segment];
         } elseif (is_object($target)) {
             if (!isset($target->{$segment})) {
                 return value($default);
             }
             $target = $target->{$segment};
         } else {
             return value($default);
         }
     }
     return $target;
 }