@Sofia Having “domain” methods on models like that is fine, and is something I do myself.
I think worrying about updating “dirty” fields is a non-issue, though. That’s literally how the Active Record pattern (which Eloquent is based on) works. Trying to avoid that behaviour would be removing the very fabric Eloquent is built on. It also doesn’t really make sense to “touch” attributes without saving them, and then call a method that does save the model and all of its dirty attributes:
// This code doesn't really make sense...
$card->foo = 'bar';
$card->bar = 'foo';
$card->qux = 'qux';
$card->ban();
I’ll also usually dispatch an event, rather than doing side effects in business logic methods like this:
class Card extends Model
{
public function ban(): bool
{
$banned = $this->forceFill([
'banned_at' => $this->freshTimestamp(),
'banning_reason' => 'Hacked',
])->save();
CardBanned::dispatchIf($banned, $this);
return $banned;
}
}
The CardBanned event can then have listeners that send notifications, do any clean-up actions, etc.