laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.41k stars 10.99k forks source link

Collection::forget not accepting Collection as parameter #47571

Closed puggan closed 1 year ago

puggan commented 1 year ago

Laravel Version

9.30.1

PHP Version

8.2.7

Database Driver & Version

No response

Description

Collection::forget not accepting Collection as parameter

https://github.com/laravel/framework/blob/aef89589ea70e0081c139b06550220cc75f20ea6/src/Illuminate/Collections/Collection.php#L430-L437

as the Collection::keys return a collection of keys, I expect methods taking keys as input also takes collection of keys.

Steps To Reproduce

$a = (new \Illuminate\Support\Collection([7 => ['c' => 9], 9 => ['c' => 2]]))
$a->forget($a->where('c', '>', 8)->keys() /*->all()*/)
milwad-dev commented 1 year ago

You mean add the ability to pass collection for the forget method in Collection, like this:

    $collection = collect([
        'name' => 'taylor',
        'framework' => 'laravel',
        'age' => 18,
        'job' => 'software engineer',
        'frontend' => 'VueJS',
    ]);
    $remColl = collect(['age', 'frontend']);

    $collection->forget($remColl);

/*
    "name" => "taylor"
    "framework" => "laravel"
    "job" => "software engineer"
/*
hypnodev commented 1 year ago

Why not use reject?

        $a = (new Collection([7 => ['c' => 9], 9 => ['c' => 2]]));
        $filtered = $a->reject(function ($value) {
            return $value['c'] > 8;
        });
        $filtered->all(); // [9 => ['c' => 2]]