optional() helper now supports a callback

Submitted by laraning - 5 years ago

The optional helper now can have a callback to execute in case the first argument is null.

In Laravel 5.6.13 you can use the optional with a 2nd argument that is executed 
in case the first one returns null.

$a = null;

$b = optional($a, function($test) { return 'hi there!'; });

Result:
$b = 'hi there'

Hope it helps!

Bruno Falcão
www.laraning.com
@_laraning