Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[9.x] Replace foreach by collection contains in Request class #39857

Merged
merged 1 commit into from
Dec 1, 2021

Conversation

seriquynh
Copy link
Contributor

Because http component requires illuminate/collections package, we can use collection inside Request class. One more thing is Laravel v9 requires PHP >= 8.0, we also can use arrow functions right here. In this pull request, I replace two foreach statements by two one-line collection contains method.

Before

foreach ($patterns as $pattern) {
    if (Str::is($pattern, $path)) {
        return true;
    }
}

return false;

After

return collect($patterns)->contains(fn ($pattern) => Str::is($pattern, $path));

@taylorotwell taylorotwell merged commit 6cb52b2 into laravel:master Dec 1, 2021
@seriquynh seriquynh deleted the repleace-foreach branch June 14, 2024 01:09
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants