Laravel 8 with() {#collection-method}
with 函数返回给定的值。如果传递了一个 闭包 给第二个参数,那么会返回 闭包 执行的结果:
$callback = function ($value) {
return (is_numeric($value)) ? $value * 2 : 0;
};
$result = with(5, $callback);
// 10
$result = with(null, $callback);
// 0
$result = with(5, null);
// 5