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

Laravel Bannable Laravel Package

qirolab/laravel-bannable

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Modularity: The package aligns well with Laravel’s Eloquent ORM, enabling soft-deletion-like banning for any model without invasive architectural changes. Ideal for systems requiring temporary or permanent blocking (e.g., user accounts, organizations, or content).
  • Separation of Concerns: Banning logic is encapsulated in traits (Bannable) and service providers, reducing clutter in core model logic.
  • Extensibility: Supports customization via events (BannableEvent), hooks, and middleware, making it adaptable to complex workflows (e.g., audit logging, notifications).
  • Database Agnostic: Works with any Laravel-supported database, though assumes standard table structures (no schema migrations provided).

Integration Feasibility

  • Low Coupling: Requires minimal changes to existing models (add use Bannable trait and bannable() method). No forced dependency injection or service container overrides.
  • Event-Driven: Leverages Laravel’s event system for pre/post-ban actions (e.g., triggering notifications or syncing with external services).
  • Middleware Support: Can integrate with Laravel’s middleware pipeline to enforce bans at the HTTP layer (e.g., BanCheckMiddleware).

Technical Risk

  • Schema Assumptions: Assumes models have a deleted_at column (for soft bans) or a custom banned_at column. Risk: Schema conflicts if the package isn’t configured to use a dedicated column (e.g., banned_at vs. deleted_at).
  • Soft vs. Hard Bans: Defaults to soft bans (nullable banned_at). Hard bans require additional logic (e.g., banned_until or boolean flags). Risk: Misalignment with business requirements for permanent bans.
  • Query Scope Overhead: Adds a global scope (BannableScope) to exclude banned records by default. Risk: Performance impact if not scoped properly (e.g., withTrashed() or forceDeleted()).
  • Testing Gaps: Limited test coverage for edge cases (e.g., concurrent bans, partial model updates). Risk: Undiscovered race conditions in high-write environments.
  • Laravel Version Lock: Last release in 2026 suggests potential drift from newer Laravel versions (e.g., 10.x+). Risk: Compatibility issues with future Laravel updates.

Key Questions

  1. Schema Strategy:

    • Will the package use deleted_at (soft delete) or a custom banned_at column? How will this interact with existing soft-delete logic?
    • For hard bans, how will the system distinguish between "banned" and "archived/deleted" states?
  2. Scope Behavior:

    • Should banned records be excluded by default (current behavior) or require explicit opt-in (e.g., withBanned())?
    • How will this interact with API responses (e.g., pagination, filtering)?
  3. Event Handling:

    • Are there existing event listeners for BannableEvent? How will custom logic (e.g., Slack alerts, CRM updates) be integrated?
    • What’s the fallback if an event handler fails (e.g., transaction rollback)?
  4. Performance:

    • How will banned records be handled in bulk operations (e.g., Model::where(...)->update())? Will the scope interfere?
    • Are there plans to add database indexes for banned_at columns?
  5. Rollback/Undo:

    • Is there a mechanism to "unban" models? If so, how will this be versioned or audited?
  6. Testing:

    • What’s the test coverage for concurrent operations (e.g., two users banning the same model simultaneously)?
    • Are there integration tests with Laravel’s caching (e.g., Eloquent model caching)?

Integration Approach

Stack Fit

  • Laravel Ecosystem: Seamless integration with Eloquent, Events, Middleware, and Service Providers. No external dependencies beyond Laravel core.
  • PHP Version: Compatible with PHP 8.0+ (based on Laravel 8+ support). Note: Verify compatibility with legacy PHP 7.4 if needed.
  • Database: Works with MySQL, PostgreSQL, SQLite, etc., but assumes standard table structures. Consideration: Custom migrations may be needed for non-standard schemas.
  • Caching: No built-in caching layer, but can be extended via events (e.g., cache invalidation on ban/unban).

Migration Path

  1. Assessment Phase:
    • Audit existing models to identify candidates for banning (e.g., User, Organization).
    • Decide on schema strategy (banned_at vs. deleted_at) and document conflicts.
  2. Proof of Concept:
    • Implement the trait on a non-critical model (e.g., TestGroup) and test:
      • Soft/hard ban behavior.
      • Query scopes (e.g., Model::banned()).
      • Event triggers (e.g., Banned, Unbanned).
  3. Incremental Rollout:
    • Start with read-heavy models (e.g., content bans) before applying to write-heavy models (e.g., user accounts).
    • Use feature flags to toggle banning logic during transition.
  4. Middleware Integration:
    • Add BanCheckMiddleware to API routes to block access to banned resources early.
    • Example:
      Route::middleware(['auth', 'banned'])->group(function () {
          // Protected routes
      });
      

Compatibility

  • Laravel Versions: Officially supports 8.x–10.x (based on 2026 release date). Action: Test with your Laravel version; patch if needed.
  • Package Conflicts: No known conflicts with popular Laravel packages (e.g., Spatie’s Laravel-Permission). Action: Check for trait/method name collisions.
  • Customization: Override default behavior via:
    • Custom events (e.g., BannableEvent::extend()).
    • Modified scopes (e.g., extendBannableScope()).
    • Custom middleware (e.g., BanCheckMiddleware).

Sequencing

  1. Schema Changes (if needed):
    • Add banned_at column (nullable timestamp) to target models.
    • Example migration:
      Schema::table('organizations', function (Blueprint $table) {
          $table->timestamp('banned_at')->nullable()->after('deleted_at');
      });
      
  2. Model Integration:
    • Add use Bannable; and bannable() method to models.
    • Example:
      class Organization extends Model
      {
          use Bannable;
      
          public function bannable()
          {
              return $this; // or return custom logic
          }
      }
      
  3. Event Listeners:
    • Register listeners for BannableEvent (e.g., send notifications, log actions).
    • Example:
      Event::listen(BannableEvent::class, function ($event) {
          Log::info("Model {$event->model->id} banned by {$event->user->id}");
      });
      
  4. Middleware:
    • Add BanCheckMiddleware to relevant routes/groups.
  5. Testing:
    • Validate edge cases (e.g., banned models in relationships, API responses).
    • Load test with banned records to check query performance.

Operational Impact

Maintenance

  • Dependency Updates:
    • Monitor Laravel and PHP version support. Action: Subscribe to package release notes or fork if maintenance stalls.
    • Risk: Abandoned package (0 dependents, last release in 2026). Mitigation: Plan for self-hosting or forking if critical.
  • Schema Management:
    • Future-proof banned_at column (e.g., add banned_until for temporary bans).
    • Action: Document schema changes in migration files.
  • Event Handlers:
    • Centralize event listeners in a dedicated service (e.g., BanEventHandler) for easier maintenance.

Support

  • Debugging:
    • Use BannableEvent payloads to trace banning logic (e.g., who banned, when, why).
    • Tooling: Add TTL-based logs for banned models to track issues.
  • User Support:
    • Provide admin UI to view banned models and reasons (e.g., BannedModel::withReasons()).
    • Example:
      // Admin route to list banned models
      Route::get('/admin/banned', function () {
          return BannedModel::with('bannedBy')->get();
      });
      
  • Documentation:
    • Gap: Limited real-world examples in README. Action: Create internal docs for:
      • Custom scope usage.
      • Event extension patterns.
      • Middleware configuration.

Scaling

  • Database Load:
    • Risk: Global scope (BannableScope) may add overhead to all queries. Mitigation:
      • Use database indexes on banned_at.
      • Avoid global scopes in high-traffic read paths (e.g., use withBanned() explicitly).
    • Optimization: Cache banned model
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