miggi
295
4
Laravel

first truthy callback result

Posted 3 months ago by miggi

Hi, guys! I need to get the result of first call to byStock method that returns not null value. but this code gives me the name of the class, not the discount itself.

public function calculateDiscount()
    {
        $this->discount = Arr::first([
            ActiveProductDiscount::class,
            ActiveManufacturerDiscount::class,
            ActiveProductGroupDiscount::class,
            ActivePriceGroupDiscount::class,
        ], function ($class) {
            return $class::byStock($this);
        });
    }

Please sign in or create an account to participate in this conversation.