Illuminate\Support\Collection::reject PHP Method

reject() public method

Create a collection of all elements that do not pass a given truth test.
public reject ( callable | mixed $callback ) : static
$callback callable | mixed
return static
    public function reject($callback)
    {
        if ($this->useAsCallable($callback)) {
            return $this->filter(function ($value, $key) use($callback) {
                return !$callback($value, $key);
            });
        }
        return $this->filter(function ($item) use($callback) {
            return $item != $callback;
        });
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Compile the final form
  *
  * @return string
  */
 protected function generateForm()
 {
     $form = $this->generateTag($this->form->pull(0));
     /**
      * Remove Empty Items
      */
     $this->form = $this->form->reject(function ($obj) {
         return $obj instanceof Collection ? $obj->isEmpty() : false;
     });
     return $this->form->map(function ($item) {
         /**
          * Remove ErrorBox if there is no error
          */
         if ($item instanceof Collection && $item->get('element') == 'errorMessage' && $item->get('errors') === null) {
             return false;
         }
         /**
          * Generate tag if $item is not empty
          */
         if ($item instanceof Collection) {
             /**
              * Detect Errors
              */
             $error = $this->appendErrors($item);
             return $this->wrap($item, $error);
         }
         /**
          * Return item if it`s just an string
          */
         return $item;
     })->prepend($form)->implode('');
 }
All Usage Examples Of Illuminate\Support\Collection::reject