Created
January 6, 2020 19:29
-
-
Save janzikmund/af758034a2d92c0cd3811cb5c705dd31 to your computer and use it in GitHub Desktop.
Laravel eloquent model method to enable save with composite primary key
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
/** | |
* 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