Skip to content

Instantly share code, notes, and snippets.

@jarektkaczyk
Last active February 13, 2020 11:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jarektkaczyk/fe6671e2399bf614a97a to your computer and use it in GitHub Desktop.
Save jarektkaczyk/fe6671e2399bf614a97a to your computer and use it in GitHub Desktop.
Laravel Request::only vs Collection (Arr) ::only
<?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