How to get the last element of a collection in illuminate/collections?

To get the last element of a collection in Illuminate/Collections, you can use the last() method.

Here's an example:

use Illuminate\Support\Collection; $collection = Collection::make([1, 2, 3, 4, 5]); $lastElement = $collection->last(); echo $lastElement; // Output: 5

In this example, we create a collection using Collection::make() method and pass an array of elements. Then we use the last() method to retrieve the last element from the collection, which in this case is 5.