Created
December 2, 2020 16:16
-
-
Save Braunson/3ce5d123f85b747835f5214225767fdf to your computer and use it in GitHub Desktop.
Laravel - Case your dirty attributes the same way they would be if they were using `getOriginal()`. Add this trait to your app and import it into the model you want to use it with.
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
<?php | |
namespace App\Traits; | |
trait DirtyOverride | |
{ | |
/** | |
* Get the attributes that have been changed since last sync. | |
* | |
* @return array | |
*/ | |
public function getDirty() | |
{ | |
$dirty = []; | |
foreach ($this->getAttributes() as $key => $value) { | |
if (! $this->originalIsEquivalent($key)) { | |
$dirty[$key] = $this->transformModelValue( | |
$key, $value | |
); | |
} | |
} | |
return $dirty; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment