Skip to content

Instantly share code, notes, and snippets.

@amochohan
Created April 25, 2017 10:39
Show Gist options
  • Save amochohan/f363638ae5b0cbe5ea33b2372d895a26 to your computer and use it in GitHub Desktop.
Save amochohan/f363638ae5b0cbe5ea33b2372d895a26 to your computer and use it in GitHub Desktop.
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