sebastiaanluca/laravel-boolean-dates
BooleanDates), requiring minimal changes to existing models. No database schema modifications needed.has_accepted_terms ↔ accepted_terms_at). Existing queries/serialization remain unaffected.BooleanDates trait options (e.g., custom field names, Carbon format), allowing alignment with domain-specific needs.User with millions of records).Resource classes). Risk of inconsistent client-side handling.config('app.timezone')).null values).WHERE has_accepted_terms = true vs. WHERE accepted_terms_at IS NOT NULL)?accepted_terms_at)?null or false booleans)?carbon/carbon).is_active, has_agreed_to_tos).User, Subscription) and monitor performance/behavior.BooleanDates trait on a per-model basis:
use SebastiaanLuca\BooleanDates\BooleanDates;
class User extends Model {
use BooleanDates;
protected $booleanDates = [
'has_accepted_terms' => 'accepted_terms_at',
'is_subscribed' => 'subscribed_at',
];
}
User::query()->where('has_accepted_terms', true)->update(['accepted_terms_at' => now()]);
Resource classes or API responses to exclude boolean fields if dates are preferred:
public function toArray($request) {
return [
'accepted_terms_at' => $this->accepted_terms_at,
// Omit 'has_accepted_terms'
];
}
$user->has_accepted_terms) remains functional.spatie/laravel-activitylog or laravel-medialibrary.config/app.php) match expectations.accepted_terms_at for compliance, has_accepted_terms for legacy code").sebastiaanluca/laravel-boolean-dates package (MIT license allows forks if needed).$booleanDates mapping require updates to all affected models. Consider a shared config or base model to centralize definitions.null booleans, time zone conversions).accepted_terms_at in new code").updateOrCreate or queue-based jobs.accepted_terms_at).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Carbon timezone misconfiguration | Inconsistent timestamps across environments | Enforce config('app.timezone') in CI/CD and use Carbon::setTestNow(). |
| Serialization leaks | API clients receive both boolean and date fields | Use Resource classes or API filters to exclude booleans. |
| Database migration errors | Backfill scripts fail on large datasets | Batch updates and monitor queue workers. |
| Package deprecation | Package is abandoned | Fork the repository or migrate to a custom solution (e.g., model observers). |
| Boolean-to-date logic bugs | Incorrect timestamps (e.g., false → future date) |
Add validation in mutators (e.g., if (!$value) return null;). |
accepted_terms_at in audit logs").How can I help you explore Laravel packages today?