Laravel 在集合过滤中更改变量

Laravel change variable within collection filtering

有没有像这样在集合过滤中制作$var = 7

$var = 1;

$collection->filter(function( $q ) use ($var){
    if( true ){
        $var = 7;
        return true;
    }
});

dd( $var );

目前这不起作用,我得到的仍然是1

我也试过使用 global 但我仍然得到 1

传递变量by reference,然后它会被改变,例如

$collection->filter(function( $q ) use (&$var){
                                      //^ See here