Skip to content

Commit 9845d4b

Browse files
New when() helper. (#52665)
* feat(blade): New @when directive. * StyleCI * fix: move to compilesConditionals + remove default expression * fix: styleCI * fix: when() returns the value, rather than echoing it. * fix: Remove @throws tags * fix: styleCI * fix: escaping on by default * fix: remove blade directive and adds tests for when helper * StyleCI * remove default, add more tests. * Remove return type * StyleCI * Update helpers.php * move function --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 66d2c9b commit 9845d4b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

helpers.php

+18
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,21 @@ function value($value, ...$args)
236236
return $value instanceof Closure ? $value(...$args) : $value;
237237
}
238238
}
239+
240+
if (! function_exists('when')) {
241+
/**
242+
* Output a value if the given condition is true.
243+
*
244+
* @param mixed $condition
245+
* @param \Closure|mixed $output
246+
* @return mixed
247+
*/
248+
function when($condition, $output)
249+
{
250+
if ($condition) {
251+
return value($output);
252+
}
253+
254+
return null;
255+
}
256+
}

0 commit comments

Comments
 (0)