Performing a partial update
This file contains 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