optional() helper now supports a callback

Submitted by laraning - 4 months 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
comments powered by Disqus