public function storeWhiteList(array $rules)
    {
        $storedRules   = $this->repository->getEnabledWhitelist();
        $rulesToUpdate = [];
        $rulesToRemove = [];

        foreach ($storedRules as $storedRule) {
            $rule = $storedRule->getValue();
            $key  = array_search($rule, $rules, true);

            if ($key === false) {
                $rulesToRemove[] = $rule;
            } else if (in_array($rule, $rules, true)) {
                $rulesToUpdate[] = $rule;

                unset($rules[$key]);
            }
        }

        $rulesToStore = $rules;

        if (count($rulesToUpdate)) {
            Rule::query()->whereIn('value', $rulesToUpdate)->update(['expired_at' => null, 'status' => 1]);
        }

        if (count($rulesToStore)) {
            $date = Carbon::now();

            $rulesToStore = array_map(function($value) use($date) {
                return [
                    'value'      => $value,
                    'trusted'    => true,
                    'user_id'    => auth()->user()->getAuthIdentifier(),
                    'created_at' => $date->toDateTimeString(),
                    'status'     => 1,
                ];
            }, $rulesToStore);

            Rule::query()->insert($rulesToStore);
        }

        if (count($rulesToRemove)) {
            Rule::query()->whereIn('value', $rulesToRemove)->delete();
        }
    }
public function storeWhiteList(array $rules)
    {
        $storedRules   = $this->repository->getEnabledWhitelist();
        $rulesToUpdate = [];
        $rulesToRemove = [];

        foreach ($storedRules as $storedRule) {
            $rule = $storedRule->getValue();
            $key  = array_search($rule, $rules, true);

            if ($key === false) {
                $rulesToRemove[] = $rule;
            } else if (in_array($rule, $rules, true)) {
                $rulesToUpdate[] = $rule;

                unset($rules[$key]);
            }
        }

        $rulesToStore = $rules;

        if (count($rulesToUpdate)) {
            Rule::query()->whereIn('value', $rulesToUpdate)->update(['expired_at' => null, 'status' => 1]);
        }

        if (count($rulesToStore)) {
            $date = Carbon::now();

            $rulesToStore = array_map(function($value) use($date) {
                return [
                    'value'      => $value,
                    'trusted'    => true,
                    'user_id'    => auth()->user()->getAuthIdentifier(),
                    'created_at' => $date->toDateTimeString(),
                    'status'     => 1,
                ];
            }, $rulesToStore);

            Rule::query()->insert($rulesToStore);
        }

        if (count($rulesToRemove)) {
            Rule::query()->whereIn('value', $rulesToRemove)->delete();
        }
    }
public function storeWhiteList ( array $ rules ) { $ storedRules = $ this -> repository -> getEnabledWhitelist ( ) ; $ rulesToUpdate = [ ] ; $ rulesToRemove = [ ] ; foreach ( $ storedRules as $ storedRule ) { $ rule = $ storedRule -> getValue ( ) ; $ key = array_search ( $ rule , $ rules , true ) ; if ( $ key === false ) { $ rulesToRemove [ ] = $ rule ; } else if ( in_array ( $ rule , $ rules , true ) ) { $ rulesToUpdate [ ] = $ rule ; unset ( $ rules [ $ key ] ) ; } } $ rulesToStore = $ rules ; if ( count ( $ rulesToUpdate ) ) { Rule :: query ( ) -> whereIn ( 'value' , $ rulesToUpdate ) -> update ( [ 'expired_at' => null , 'status' => 1 ] ) ; } if ( count ( $ rulesToStore ) ) { $ date = Carbon :: now ( ) ; $ rulesToStore = array_map ( function ( $ value ) use ( $ date ) { return [ 'value' => $ value , 'trusted' => true , 'user_id' => auth ( ) -> user ( ) -> getAuthIdentifier ( ) , 'created_at' => $ date -> toDateTimeString ( ) , 'status' => 1 , ] ; } , $ rulesToStore ) ; Rule :: query ( ) -> insert ( $ rulesToStore ) ; } if ( count ( $ rulesToRemove ) ) { Rule :: query ( ) -> whereIn ( 'value' , $ rulesToRemove ) -> delete ( ) ; } }
Handles the store action for whitelist rules.

@param array $rules
Handles the store action for whitelist rules .