Skip to content

Instantly share code, notes, and snippets.

@MrMadClown
Created May 12, 2020 14:07
Show Gist options
  • Save MrMadClown/9dfec90263482036f9922c56de35dd36 to your computer and use it in GitHub Desktop.
Save MrMadClown/9dfec90263482036f9922c56de35dd36 to your computer and use it in GitHub Desktop.
\Illuminate\Database\Eloquent\Concerns\HasAttributes::originalIsEquivalent object cast comparison
class Ticket extends Model {
protected $casts = [
'content' => 'object',
];
}
$ticket = new Ticket();
$ticket->content = \json_decode('{"key":""}');
$ticket->save();
var_dump($ticket->refresh()->content); // object(stdClass)#1 (1) { ["key"]=> string(0) "" }
$ticket = new Ticket();
$ticket->content = \json_decode('{"key":null}');
$ticket->save(); // No attributes are considered Dirty
var_dump($ticket->refresh()->content); // object(stdClass)#1 (1) { ["key"]=> string(0) "" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment