Last active
February 13, 2020 11:16
-
-
Save jarektkaczyk/fe6671e2399bf614a97a to your computer and use it in GitHub Desktop.
Laravel Request::only vs Collection (Arr) ::only
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// given input ['name' => 'jarek'] | |
Request::only('name', 'email') | |
[ | |
"name" => "jarek", | |
"email" => null, // even if empty in the input, the key will be here | |
] | |
collect(['name'=>'jarek'])->only('name', 'email') | |
Illuminate\Support\Collection {#984 | |
all: [ | |
"name" => "jarek", // only keys from input are here | |
], | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment