mirror of
https://github.com/getformwork/formwork.git
synced 2025-02-24 17:52:41 +01:00
Fix Collection::first()
and Collection::last()
on empty case
This commit is contained in:
parent
c5cc1fbcf3
commit
9be7b800cb
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user