Illuminate\Support\Collection::last PHP Method

last() public method

Get the last item from the collection.
public last ( callable $callback = null, mixed $default = null ) : mixed
$callback callable
$default mixed
return mixed
    public function last(callable $callback = null, $default = null)
    {
        return Arr::last($this->items, $callback, $default);
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Handle every iteration of the parsing process.
  *
  * @param  \pandaac\Exporter\Contracts\Reader  $reader
  * @param  \Illuminate\Support\Collection  $collection
  * @return \Illuminate\Support\Collection
  */
 public function iteration(Reader $reader, Collection $collection)
 {
     // Item information
     if ($iteration = $this->item($reader)) {
         $collection->push($iteration);
     }
     if (!($reader->isElement() or $reader->isAttribute())) {
         return $collection;
     }
     if ($this->enabled('attributes')) {
         // Item attributes
         if ($iteration = $this->itemAttributes($reader)) {
             $item = $collection->last();
             if (!$item->get('attributes')) {
                 $item->put('attributes', new Collection());
             }
             $item->get('attributes')->push($iteration);
             return $collection;
         }
         if ($this->enabled('properties')) {
             // Item attribute properties
             if ($iteration = $this->itemAttributeProperties($reader)) {
                 $attribute = $collection->last()->get('attributes')->last();
                 if (!$attribute->get('properties')) {
                     $attribute->put('properties', new Collection());
                 }
                 $attribute->get('properties')->push($iteration);
                 return $collection;
             }
         }
     }
     return $collection;
 }
All Usage Examples Of Illuminate\Support\Collection::last