PHPackages                             thefeqy/laravel-model-status - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. thefeqy/laravel-model-status

ActiveLibrary[Database &amp; ORM](/categories/database)

thefeqy/laravel-model-status
============================

A Laravel package to automate adding configurable status columns to models and migrations, and enforce user activity through middleware.

v1.5.0(1y ago)504971MITPHPPHP ^8.3|^8.4CI passing

Since Jan 17Pushed 1y ago1 watchersCompare

[ Source](https://github.com/thefeqy/laravel-model-status)[ Packagist](https://packagist.org/packages/thefeqy/laravel-model-status)[ GitHub Sponsors](https://github.com/thefeqy)[ RSS](/packages/thefeqy-laravel-model-status/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (7)Versions (8)Used By (0)

🔁 Laravel Model Status
======================

[](#-laravel-model-status)

[![Laravel Model Status](assets/images/laravel-model-status.png)](assets/images/laravel-model-status.png)

[![Latest Version on Packagist](https://camo.githubusercontent.com/16463e1a2d4d7b59a1011d97a10e3a768e1e95c0cbc2f85a61aeb7af8c660d5e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746865666571792f6c61726176656c2d6d6f64656c2d7374617475732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/thefeqy/laravel-model-status)[![Total Downloads](https://camo.githubusercontent.com/50b0309352e0df3a70b58ce1c895e7cef3957f007804fbc1a9975ee7ac30ebc8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746865666571792f6c61726176656c2d6d6f64656c2d7374617475732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/thefeqy/laravel-model-status)[![PHP Version](https://camo.githubusercontent.com/c8d8dad6beb757a2b8acba331d16140813699543b88a37af0a81f20bd35f61de/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e332532422d626c7565)](https://php.net)[![GitHub Workflow Status](https://github.com/thefeqy/laravel-model-status/actions/workflows/run-tests.yml/badge.svg)](https://github.com/thefeqy/laravel-model-status/actions/workflows/run-tests.yml/badge.svg)[![License](https://camo.githubusercontent.com/88e1dabf4d223df0950e0985948e231325fefca9fa7fe9e446cf8b1c5e9d9e47/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e)](LICENSE)

A Laravel package that simplifies **status management** for Eloquent models.

---

**Table of Contents**
---------------------

[](#table-of-contents)

- [Features](#features)
- [Installation](#installation)

    - [Step 1: Run the Installation Command](#step-1-run-the-installation-command)
- [Configuration](#configuration)

    - [Using `.env` Variables](#using-env-variables)
- [Usage](#usage)

    - [Using the `HasActiveScope` Trait](#using-the-hasactivescope-trait)
    - [Querying Models](#querying-models)
    - [Using Status Casting](#using-status-casting)
    - [Cascade Deactivation](#cascade-deactivation)
    - [Using the Middleware](#using-the-middleware)
    - [Add Middleware to Routes](#add-middleware-to-routes)
- [Admin Bypass for Active Scope](#admin-bypass-for-active-scope)
- [Advanced Configuration](#advanced-configuration)
- [Testing](#testing)
- [Security](#security)
- [Contributing](#contributing)
- [License](#license)

---

Features
--------

[](#features)

- **`HasActiveScope` Trait**: Automatically filters models with active status.
- **Admin Bypass**: Admin users can see all models, including inactive ones.
- **Helper Methods**: `$model->status->isActive()` and `$model->status->isInactive()`.
- **Dynamic Configuration**: Define custom statuses &amp; column names via `.env`.
- **Installation Command**: `php artisan model-status:install` for easy setup.
- **PHP 8.3 Support**.

---

Installation
------------

[](#installation)

You can install the package via Composer:

```
composer require thefeqy/laravel-model-status
```

### Step 1: Run the Installation Command

[](#step-1-run-the-installation-command)

```
php artisan model-status:install
```

This will:

- Publish the config file (`config/model-status.php`).
- Set up required environment variables in `.env` and `.env.example`.
- Ensure your project is ready to use the package.

---

Configuration
-------------

[](#configuration)

You can customize the package settings in:

`config/model-status.php`

```
return [
    'column_name' => env('MODEL_STATUS_COLUMN', 'status'),
    'default_value' => env('MODEL_STATUS_ACTIVE', 'active'),
    'inactive_value' => env('MODEL_STATUS_INACTIVE', 'inactive'),

    'admin_detector' => function () {
        return auth()->check() && auth()->user()->is_admin;
    },
];
```

### Using .env Variables

[](#using-env-variables)

Instead of modifying `config/model-status.php`, you can override values in .env:

`.env`

```
MODEL_STATUS_COLUMN=state
MODEL_STATUS_ACTIVE=enabled
MODEL_STATUS_INACTIVE=disabled
```

Now, the package will automatically adapt to your setup.

Usage
-----

[](#usage)

### Using the HasActiveScope Trait

[](#using-the-hasactivescope-trait)

To enable status management in a model:

```
use Thefeqy\ModelStatus\Traits\HasActiveScope;

class Product extends Model
{
    use HasActiveScope;

    protected $fillable = ['name'];
}
```

Now, inactive models are automatically excluded from queries.

---

### Querying Models

[](#querying-models)

Get Active Models (Default Behavior)

```
$activeProducts = Product::all(); // Returns only active products
```

Get All Models (Including Inactive)

```
$allProducts = Product::inActive()->get();
```

Manually Activating / Deactivating a Model

```
$product = Product::find(1);

$product->activate(); // Set status to "active"
$product->deactivate(); // Set status to "inactive"
```

Checking a Model's Status

```
if ($product->status->isActive()) {
    echo "Product is active!";
}

if ($product->status->isInactive()) {
    echo "Product is inactive!";
}
```

---

### Using Status Casting

[](#using-status-casting)

To ensure `status` is always cast to a `Status` object, use the `StatusCast` class.

#### Apply Status Casting in Models

[](#apply-status-casting-in-models)

```
use Thefeqy\ModelStatus\Casts\StatusCast;

class Product extends Model
{
    use HasActiveScope;

    protected $fillable = ['name', 'status', 'category_id'];

    protected $casts = [
        'status' => StatusCast::class,
    ];
}
```

#### Example Usage

[](#example-usage)

```
$product = Product::find(1);

if ($product->status->isActive()) {
    echo "Product is active!";
}
```

Now, `$product->status` is an instance of `Status`, allowing method calls like `isActive()` and `isInactive()`.

---

### Cascade Deactivation

[](#cascade-deactivation)

If a model is deactivated, its related models can also be **automatically deactivated**.

#### Example

[](#example)

```
class Category extends Model
{
    use HasActiveScope;

    protected $fillable = ['name', 'status'];

    protected array $cascadeDeactivate = ['products'];

    public function products()
    {
        return $this->hasMany(Product::class);
    }
}
```

Now, deactivating a **category** will also **deactivate all products** under it:

```
$category = Category::find(1);
$category->deactivate();
```

---

### Using the Middleware

[](#using-the-middleware)

The package includes the `EnsureAuthenticatedUserIsActive` middleware, which enforces that only users with an active status can access certain routes.

#### Add Middleware to Routes

[](#add-middleware-to-routes)

Instead of registering a string alias for the middleware, you can reference it by class name in your route definition:

```
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!';
    });
});
```

---

Admin Bypass for Active Scope
-----------------------------

[](#admin-bypass-for-active-scope)

By default, admin users can see inactive models.

This behavior is controlled in `config/model-status.php`:

```
'admin_detector' => function () {
    return auth()->check() && auth()->user()->is_admin;
},
```

---

Advanced Configuration
----------------------

[](#advanced-configuration)

If you need a different column name or status values, update `.env`:

```
MODEL_STATUS_COLUMN=state
MODEL_STATUS_ACTIVE=enabled
MODEL_STATUS_INACTIVE=disabled
```

Now, models will use:

```
$table->string('state', 10)->default('enabled');
```

instead of:

```
$table->string('status', 10)->default('active');
```

Testing
-------

[](#testing)

Run tests using Pest PHP:

```
composer test
or
vendor/bin/phpunit
```

Security
--------

[](#security)

If you discover a security vulnerability, please report it via email: 📩

Contributing
------------

[](#contributing)

Want to improve this package? Check out [CONTRIBUTING](CONTRIBUTING.md) for contribution guidelines.

License
-------

[](#license)

This package is open-source software licensed under the [MIT License](LICENSE).

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance44

Moderate activity, may be stable

Popularity26

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~7 days

Total

7

Last Release

434d ago

PHP version history (3 changes)v1.0.0PHP ^8.1

v1.2.0PHP ^8.3

1.3.0PHP ^8.3|^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/fc3f838af3b2510ebffcdd78a70884a6d15677a9b8051246c86670ca51da13a9?d=identicon)[thefeqy](/maintainers/thefeqy)

---

Top Contributors

[![thefeqy](https://avatars.githubusercontent.com/u/44809366?v=4)](https://github.com/thefeqy "thefeqy (55 commits)")

---

Tags

laravelmodel-statemodel-statusphpstatus-active

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/thefeqy-laravel-model-status/health.svg)

```
[![Health](https://phpackages.com/badges/thefeqy-laravel-model-status/health.svg)](https://phpackages.com/packages/thefeqy-laravel-model-status)
```

###  Alternatives

[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k25.9M107](/packages/laravel-cashier)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[laravel-doctrine/orm

An integration library for Laravel and Doctrine ORM

8425.3M87](/packages/laravel-doctrine-orm)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

71510.9M66](/packages/laravel-mcp)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[provydon/docs-generate

Automatic API documentation for your Laravel app — zero annotations, OpenAPI 3.0 JSON &amp; Swagger UI.

103.5k](/packages/provydon-docs-generate)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
