lundi 26 juin 2017

Remove items from array which are not in stock (laravel)

enter image description here

Each bikegroups contains electric-bikes and one group of accu's.

I want to remove a BikeGroup from this array when there is no bike or accu in stock.

I allready made the code for this and this works, i just don't know how i can remove the BikeGroup from the array...

How i call the function in my view:

<?php
    use App\Http\Controllers\WebshopController;
?>

@foreach($bikegroups as $bikegroup)
{!! WebshopController::onlyGroupsWithStock($bikegroup) !!}

Inside the webshopcontroller:

public static function onlyGroupsWithStock($bikegroup) {
    foreach($bikegroup->bikes as $bike) {
        if(isset($bike->stock) && strpos($bike->artikelcode,'EBDI') === false) {
            if($bike->stock->stockadvance->week1aantal > 0) {
                $fietsvoorraad = true;
                if($fietsvoorraad){
                    break;
                }
            }

        }
    }

    if(isset($bikegroup->accugroup)) {
        foreach($bikegroup->accugroup->UpselProducts as $product){
            foreach($product->Products as $product) {
                if(isset($product->stock)) {
                    if($product->stock->stockadvance->week1aantal > 0) {
                        $accuvoorraad = true;
                        if($accuvoorraad) {
                            break;
                        }
                    }
                }

            }
        }
    } else {
        $accuvoorraad = true;
    }

    if(isset($fietsvoorraad) && $fietsvoorraad && isset($accuvoorraad) && $accuvoorraad) {

    } else {
        return "STOCK FOR BIKE OF ACCU REMOVE FROM BIKEGROUP";
    }

}

Any help is appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire