Skip to content

Instantly share code, notes, and snippets.

@amochohan amochohan/pick.php
Created Apr 25, 2017

Embed
What would you like to do?
Performing a partial update
<?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
You can’t perform that action at this time.