Fix Collection::first() and Collection::last() on empty case

This commit is contained in:
Giuseppe Criscione 2019-05-30 18:05:53 +02:00
parent c5cc1fbcf3
commit 9be7b800cb

View File

@ -92,18 +92,22 @@ class Collection implements Countable, Iterator
/**
* Return first collection item
*
* @return mixed|null
*/
public function first()
{
return $this->items[0];
return $this->items[0] ?? null;
}
/**
* Return last collection item
*
* @return mixed|null
*/
public function last()
{
return $this->items[$this->count() - 1];
return $this->items[$this->count() - 1] ?? null;
}
/**