Skip to content

Instantly share code, notes, and snippets.

@MECU
Created April 7, 2017 19:40
Show Gist options
  • Save MECU/556b2351d347113774a5097a20930f35 to your computer and use it in GitHub Desktop.
Save MECU/556b2351d347113774a5097a20930f35 to your computer and use it in GitHub Desktop.
Laravel Pivot multiple updated
$lane = $race->teams()->wherePivot('lane', $row[2])->find($team->id);
// See status before saving input results
Log::debug($lane->pivot);
// Update the place and result (time)
$lane->pivot->place = $row[0];
$lane->pivot->result = $row[6];
// Output changes
Log::debug($lane->pivot);
$lane->pivot->save();
// Output in logfile
[2017-04-07 19:35:24] prod.DEBUG: {"race_id":588,"competitor_id":85,"id":5729,"lane":1,"result":null,"place":null}
[2017-04-07 19:35:24] prod.DEBUG: {"race_id":588,"competitor_id":85,"id":5729,"lane":1,"result":"10.68","place":"1"}
[2017-04-07 19:35:24] prod.DEBUG: Row successfully processed for team, lane 1, Abington: 1: 10.68
[2017-04-07 19:35:24] prod.DEBUG: {"race_id":588,"competitor_id":79,"id":5730,"lane":2,"result":null,"place":null}
[2017-04-07 19:35:24] prod.DEBUG: {"race_id":588,"competitor_id":79,"id":5730,"lane":2,"result":"10.81","place":"2"}
[2017-04-07 19:35:24] prod.DEBUG: Row successfully processed for team, lane 2, Wissahickon: 2: 10.81
// Lane 4 was already updated when lane 2 was saved.
[2017-04-07 19:35:24] prod.DEBUG: {"race_id":588,"competitor_id":79,"id":5732,"lane":4,"result":"10.81","place":"2"}
[2017-04-07 19:35:24] prod.DEBUG: {"race_id":588,"competitor_id":79,"id":5732,"lane":4,"result":"11.12","place":"3"}
[2017-04-07 19:35:24] prod.DEBUG: Row successfully processed for team, lane 4, Wissahickon: 3: 11.12
[2017-04-07 19:35:24] prod.DEBUG: {"race_id":588,"competitor_id":78,"id":5731,"lane":3,"result":null,"place":null}
[2017-04-07 19:35:24] prod.DEBUG: {"race_id":588,"competitor_id":78,"id":5731,"lane":3,"result":"11.33","place":"4"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment