Created
April 25, 2017 10:39
-
-
Save amochohan/f363638ae5b0cbe5ea33b2372d895a26 to your computer and use it in GitHub Desktop.
Performing a partial update
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 | |
MyController extends Controller | |
{ | |
public function store(Request $request) | |
{ | |
$interaction = Interaction::create($this->pick((new Interaction)->getFillable(), $request); | |
} | |
/** | |
* Get a subset containing the provided keys with values from the input data. | |
* | |
* @param array|mixed $keys | |
* @param Request $request | |
* @return array | |
*/ | |
protected function pick($keys, $request) | |
{ | |
$keys = is_array($keys) ? $keys : func_get_args(); | |
return array_intersect_key($request->all(), array_flip($keys)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment