Bannable) and service providers, reducing clutter in core model logic.BannableEvent), hooks, and middleware, making it adaptable to complex workflows (e.g., audit logging, notifications).use Bannable trait and bannable() method). No forced dependency injection or service container overrides.BanCheckMiddleware).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).banned_at). Hard bans require additional logic (e.g., banned_until or boolean flags). Risk: Misalignment with business requirements for permanent bans.BannableScope) to exclude banned records by default. Risk: Performance impact if not scoped properly (e.g., withTrashed() or forceDeleted()).Schema Strategy:
deleted_at (soft delete) or a custom banned_at column? How will this interact with existing soft-delete logic?Scope Behavior:
withBanned())?Event Handling:
BannableEvent? How will custom logic (e.g., Slack alerts, CRM updates) be integrated?Performance:
Model::where(...)->update())? Will the scope interfere?banned_at columns?Rollback/Undo:
Testing:
User, Organization).banned_at vs. deleted_at) and document conflicts.TestGroup) and test:
Model::banned()).Banned, Unbanned).BanCheckMiddleware to API routes to block access to banned resources early.Route::middleware(['auth', 'banned'])->group(function () {
// Protected routes
});
BannableEvent::extend()).extendBannableScope()).BanCheckMiddleware).banned_at column (nullable timestamp) to target models.Schema::table('organizations', function (Blueprint $table) {
$table->timestamp('banned_at')->nullable()->after('deleted_at');
});
use Bannable; and bannable() method to models.class Organization extends Model
{
use Bannable;
public function bannable()
{
return $this; // or return custom logic
}
}
BannableEvent (e.g., send notifications, log actions).Event::listen(BannableEvent::class, function ($event) {
Log::info("Model {$event->model->id} banned by {$event->user->id}");
});
BanCheckMiddleware to relevant routes/groups.banned_at column (e.g., add banned_until for temporary bans).BanEventHandler) for easier maintenance.BannableEvent payloads to trace banning logic (e.g., who banned, when, why).BannedModel::withReasons()).// Admin route to list banned models
Route::get('/admin/banned', function () {
return BannedModel::with('bannedBy')->get();
});
BannableScope) may add overhead to all queries. Mitigation:
banned_at.withBanned() explicitly).How can I help you explore Laravel packages today?