The Laravel Model Status package by Muhammed ElFeqy automates adding configurable status columns to models and migrations. This package provides an easy-to-use HasActiveScope
trait, a Status
enum, middleware for ensuring active users, and a custom Artisan command to streamline your workflow.
use Thefeqy\ModelStatus\Traits\HasActiveScope; class ExampleModel extends Model{ use HasActiveScope; protected $fillable = ['name'];} $model->activate(); // Give the model an active status$model->deactivate(); // Deactivate the model // Only active models$activeModels = ExampleModel::all(); // Include inactive models$allModels = ExampleModel::withoutActive()->get();
This model also includes a middleware, which enforces a route that can only be accessed by users with an active status. The EnsureAuthenticatedUserIsActive
in this example will log the user out and send them a 403 Forbidden response
if their account is inactive:
use Illuminate\Support\Facades\Route;use Thefeqy\ModelStatus\Middleware\EnsureAuthenticatedUserIsActive; Route::middleware(['auth', EnsureAuthenticatedUserIsActive::class]) ->group(function () { Route::get('/dashboard', function () { return 'Welcome to your dashboard!'; }); });
Main Features
- Add a configurable status column to models and migrations.
- Automatically handle global scopes for active statuses.
- Enforce user activity with the EnsureAuthenticatedUserIsActive middleware.
- Activate or deactivate models with simple methods.
- Support dynamic configuration for the column name, default value, and length.
- Includes a make:model-status command.
You can learn more about this package, get full installation instructions, and view the source code on GitHub. You can install this package in your project via Composer using the following command:
composer require thefeqy/laravel-model-status