Skip to content

Instantly share code, notes, and snippets.

@janzikmund
Created January 6, 2020 19:29
Show Gist options
  • Save janzikmund/af758034a2d92c0cd3811cb5c705dd31 to your computer and use it in GitHub Desktop.
Save janzikmund/af758034a2d92c0cd3811cb5c705dd31 to your computer and use it in GitHub Desktop.
Laravel eloquent model method to enable save with composite primary key
/**
* Set the composite keys for a save update query.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
protected function setKeysForSaveQuery(Builder $query)
{
$query
->where('user_id', '=', $this->getAttribute('user_id'))
->where('date', '=', $this->getAttribute('date'))
->where('slot', '=', $this->getAttribute('slot'));
return $query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment