Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Bypass Readonly

Bypass Readonly Laravel Package

zoltanka/bypass-readonly

PHPUnit plugin that lets you bypass PHP readonly and final restrictions for testing. Useful when you need to mock, extend, or modify classes marked final/readonly without changing production code. Inspired by dg/bypass-finals.

View on GitHub
Deep Wiki
Context7

At a glance

Frequently asked questions about Bypass Readonly
How do I install zoltanka/bypass-readonly for Laravel testing?
Run `composer require --dev zoltanka/bypass-readonly` in your project. The package integrates directly with PHPUnit and requires no additional Laravel service provider or configuration. Ensure your PHP version is 7.4+ and Laravel is 7 or higher.
Can I bypass readonly/final constraints on Eloquent models in Laravel 10?
Yes, the package supports Laravel 10, but explicitly test compatibility since the last release was in 2023. No breaking changes are reported, but audit your models for Eloquent API updates in Laravel 10. Use it cautiously in migrations or admin operations.
What’s the best way to mock a readonly Eloquent model for testing?
Use the package’s PHPUnit extension to bypass readonly constraints temporarily. For example, extend your test class with `BypassReadonlyExtension` and annotate test methods with `@bypassReadonly`. Avoid global bypasses; scope it to specific models or test cases.
Is zoltanka/bypass-readonly safe for production use?
No, this package is designed **only for testing**. Bypassing readonly/final constraints in production can break data integrity. Use it exclusively in test environments, and combine with Laravel’s `authorize()` gates or role-based checks if needed.
How do I handle database constraint violations when bypassing readonly?
The package bypasses PHP-level constraints but won’t override database-level constraints (e.g., `ON UPDATE CASCADE`). Handle violations with try-catch blocks or Laravel’s `try-catch` in migrations. Log bypass operations for auditability, especially in admin interfaces like Nova or Filament.
What are the alternatives to zoltanka/bypass-readonly for Laravel?
Consider custom model events, accessors, or policies to modify behavior without bypassing constraints. For final classes, use dependency injection or interfaces. If you need a more maintained solution, explore `dg/bypass-finals` (the original inspiration) or fork this package for updates.
Will this package work with Laravel’s append/hidden attributes?
Yes, the package supports Eloquent’s append and hidden attributes. Bypassing readonly constraints won’t interfere with these features, but test thoroughly in your CI pipeline, especially if using Laravel 10’s updated Eloquent behavior.
How do I log bypass operations for debugging?
Manually log bypass operations using Laravel’s logger (e.g., `Log::info('Bypassing readonly on Model', ['model' => $model->class])`). Since the package lacks built-in logging, integrate it with Monolog or Laravel’s built-in logger for tracking misuse in non-admin contexts.
What’s the recommended approach for multi-tenant overrides with readonly models?
Use the package sparingly for tenant-specific overrides. Implement a scoped middleware or service provider to restrict bypass operations to trusted roles (e.g., admins). Avoid global bypasses, and refactor models to reduce reliance on readonly constraints where possible.
Should I fork or replace this package if it’s abandoned?
Yes, the package hasn’t been updated since 2023 and poses a high deprecation risk. Fork it for Laravel 11+ support or replace it with a custom trait/middleware. Document your fallback strategy, especially for critical bypass logic like migrations or admin operations.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
daikazu/eloquent-salesforce-objects
unseen-codes/chat
romalytar/yammi-jobs-monitoring-laravel
kisame76/filament-db-table-state
nqxcode/laravel-lucene-search
dpfx/laravel-livewire-wizards
workos/workos-php-laravel
sofa/laravel-global-scope
nawasara/auth-primitives
adhocrat-io/arkhe-main
make-dev/orca-harpoon
itsemon245/lamet
baks-dev/dashboard
amoifr/pickle-panther-bundle
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle