PHPackages                             nzesalem/lastus - 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. nzesalem/lastus

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

nzesalem/lastus
===============

A simple package to easily add and manage statuses in your laravel models

v5.0.0(3y ago)399574[2 issues](https://github.com/Nzesalem/lastus/issues)MITPHPPHP &gt;=8.1.0CI failing

Since Oct 21Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Nzesalem/lastus)[ Packagist](https://packagist.org/packages/nzesalem/lastus)[ RSS](/packages/nzesalem-lastus/feed)WikiDiscussions master Synced today

READMEChangelog (5)Dependencies (5)Versions (19)Used By (0)

Lastus
======

[](#lastus)

Easy status addition and management for your Eloquent models in Laravel.

[![Build Status](https://camo.githubusercontent.com/ad61d06b08b1b61a5d4f5e9a2901f4000b70ecfdd85dcb9176c1fb985dd35990/68747470733a2f2f7472617669732d63692e6f72672f6e7a6573616c656d2f6c61737475732e737667)](https://travis-ci.org/nzesalem/lastus)[![Latest Stable Version](https://camo.githubusercontent.com/7f6f5bfbf88b3ba31419c17962316245544abe8763208c970c0e2caba25b08e3/68747470733a2f2f706f7365722e707567782e6f72672f6e7a6573616c656d2f6c61737475732f762f737461626c652e737667)](https://packagist.org/packages/nzesalem/lastus)[![License](https://camo.githubusercontent.com/b0ed43ecc3d3c79f2e3aef985cc7f771b5b3c03b53158a845deeebdecb811484/68747470733a2f2f706f7365722e707567782e6f72672f6e7a6573616c656d2f6c61737475732f6c6963656e73652e737667)](https://packagist.org/packages/nzesalem/lastus)

What is lastus/status?
----------------------

[](#what-is-lastusstatus)

Consider you are building a forum app, you would typically have a `User` model/class. A `User` can be in different states or have different statuses at different points in time. For example when a user first registers for the forum you may want his/her status to be `unverified` indicating that the user have not verified his/her email. When the user verifies his/her email, he/she may become `active`. If the user violates one or more of the forum rules, he/she may become `suspended`, and so on.

**Lastus** package for Laravel 5 aims to handle all of this for you automatically, with minimal configuration.

- Install the package via Composer:

    ```
    $ composer require nzesalem/lastus
    ```

    The package will automatically register itself with Laravel 5.5 and later.

Database migrations
-------------------

[](#database-migrations)

Your database tables should have a `status` column defined as the `tinyInteger` type. **Lastus** automatically adds this column to your `users` table (if it doesn't already exist) when you run the `php artisan migrate` command after adding **Lastus** to your project.

You should manually generate migrations for other of your tables as needed. Below is an example of how you would add the `status` column to a `posts` table.

First run:

```
$ php artisan make:migration add_status_field_to_posts_table --table=posts
```

Then edit the generated migration file like so (usually located at `database/migrations`):

```
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddStatusFieldToPostsTable extends Migration
{
    public function up()
    {
        Schema::table('posts', function (Blueprint $table) {
            //...
            $table->tinyInteger('status')->default(0);
        });

        //...
    }
}
```

And finally run:

```
$ php artisan migrate
```

Updating your Eloquent Models
-----------------------------

[](#updating-your-eloquent-models)

Your models should use the `LastusTrait` and define a `STATUSES` array constant.

The keys of the `STATUSES` array should be in all caps and multiple words should be separated with underscore. Ideally it should follow the same naming rules and convention as [PHP constants](http://php.net/manual/en/language.constants.php).

The values of the `STATUSES` array can be any number within the `TINYINT` range.

```
use Illuminate\Foundation\Auth\User as Authenticatable;
use Nzesalem\Lastus\Traits\LastusTrait;

class User extends Authenticatable
{
    use LastusTrait;

    // Key value pair of the statuses you want your model to have
    const STATUSES = [
        'UNVERIFIED' => 0,
        'ACTIVE' => 1,
        'SUSPENDED' => 2,
        'BLOCKED' => 3,
        'PENDING_APPROVAL' => 7,
    ];

    //...
}
```

And that's it ...

Usage
-----

[](#usage)

When saving models, just set its status property to one of the keys you have defined above, but in all lower case, multiple words should be separated by a hyphen. E.g `PENDING_APPROVAL` becomes `pending-approval`. This is the format you will use most of the time when working with statuses.

```
$user = User::create([
    'name' => 'Salem Nzeukwu',
    'email' => 'email@domain.com',
    'password' => bcrypt('secret'),
    'status' => 'active', // This will be saved as '1' in the database
]);
```

Retrieving a model status:

```
echo $user->status; // This prints 'active'

// Sometime later
$user->status = 'pending-approval';
$user->save();

echo $user->status; // This now prints 'pending-approval'
```

You can get the status code whenever you need it. For example, status key strings will not work if you try to perform raw queries with them. So, in those cases you need the status codes instead:

```
$now = Carbon::now();

// Raw insert query
DB::table('users')->insert([
    'name' => 'Firstname Lastname',
    'email' => 'fake@example.com',
    'password' => bcrypt('secret'),
    'created_at' => $now,
    'updated_at' => $now,
    // Get the status code.
    'status' => User::getStatusCode('suspended'),
]);
// Raw select query
$user = User::whereRaw('status = ' . User::getStatusCode('suspended'))->first();

$user->status == 'suspended' // true
```

Getting all the defined statuses for a given model is also easy as the snippet below. We get all the defined statuses for the `User` model and display them in a select element:

```

    Select a status
    @foreach (App\User::statuses() as $status)
    {{ ucfirst($status) }}
    @endforeach

```

Or you can use the `Lastus` facade:

```
print_r(Lastus::statuses(App\User::class));
```

### Blade templates

[](#blade-templates)

You can use the `@status()` blade directive to control the visibility of elements based on the status of the currently logged in user:

```
@status('active')
    This is only visible to users with an 'active' status.
@endstatus
```

### Middleware

[](#middleware)

You can use a middleware to filter routes and route groups by status:

```
Route::group(['prefix' => 'dashboard', 'middleware' => ['status:active']], function() {
    Route::get('/', 'DashboardController@index');
});
```

License
-------

[](#license)

[Lastus](https://github.com/nzesalem/lastus) is released under the [MIT License](LICENSE).

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 83.3% 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 ~124 days

Recently: every ~227 days

Total

17

Last Release

1178d ago

Major Versions

v1.3.2 → v2.0.02019-10-01

v2.0.2 → v3.0.02020-10-13

3.0.2 → v4.0.02022-07-08

v4.0.0 → v5.0.02023-04-12

PHP version history (4 changes)v1.0.0-beta1PHP &gt;=7.0

v1.2.0PHP &gt;=7.1.3

v2.0.0PHP &gt;=7.2.0

v5.0.0PHP &gt;=8.1.0

### Community

Maintainers

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

---

Top Contributors

[![nzesalem](https://avatars.githubusercontent.com/u/4568863?v=4)](https://github.com/nzesalem "nzesalem (45 commits)")[![heavensloop](https://avatars.githubusercontent.com/u/282727?v=4)](https://github.com/heavensloop "heavensloop (6 commits)")[![davmixcool](https://avatars.githubusercontent.com/u/5640065?v=4)](https://github.com/davmixcool "davmixcool (3 commits)")

---

Tags

eloquent-modelslaravellastuslaravelmodelsstatuslastus

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nzesalem-lastus/health.svg)

```
[![Health](https://phpackages.com/badges/nzesalem-lastus/health.svg)](https://phpackages.com/packages/nzesalem-lastus)
```

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k54.9M11.6k](/packages/illuminate-database)[laravel-doctrine/orm

An integration library for Laravel and Doctrine ORM

8465.5M96](/packages/laravel-doctrine-orm)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M25](/packages/yajra-laravel-oci8)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.5M2](/packages/glushkovds-phpclickhouse-laravel)[venturedrake/laravel-crm

A free open source CRM built as a package for laravel projects

43311.2k](/packages/venturedrake-laravel-crm)[lemaur/eloquent-publishing

218.1k1](/packages/lemaur-eloquent-publishing)

PHPackages © 2026

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