Advertisement
gabolato

runSoftDelete for composite primary key in Laravel

Jul 31st, 2018
1,888
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.77 KB | None | 0 0
  1. /**
  2.    * Perform the actual delete query on this model instance.
  3.    *
  4.    * @return void
  5.    */
  6.   protected function runSoftDelete()
  7.   {
  8.     $query = $this->newQueryWithoutScopes()->where($this->getKeyName()[0], $this->attributes[$this->getKeyName()[0]])
  9.     ->where($this->getKeyName()[1], $this->attributes[$this->getKeyName()[1]]);
  10.    
  11.     $time = $this->freshTimestamp();
  12.    
  13.     $columns = [$this->getDeletedAtColumn() => $this->fromDateTime($time)];
  14.    
  15.     $this->{$this->getDeletedAtColumn()} = $time;
  16.    
  17.     if ($this->timestamps && ! is_null($this->getUpdatedAtColumn())) {
  18.       $this->{$this->getUpdatedAtColumn()} = $time;
  19.      
  20.       $columns[$this->getUpdatedAtColumn()] = $this->fromDateTime($time);
  21.     }
  22.    
  23.     $query->update($columns);
  24.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement