PHPackages                             makeabledk/laravel-eloquent-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. makeabledk/laravel-eloquent-status

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

makeabledk/laravel-eloquent-status
==================================

v4.2.0(1y ago)15378.0k—2.4%111CC-BY-SA-4.0PHPPHP ^8.1CI passing

Since Sep 5Pushed 1mo ago4 watchersCompare

[ Source](https://github.com/makeabledk/laravel-eloquent-status)[ Packagist](https://packagist.org/packages/makeabledk/laravel-eloquent-status)[ RSS](/packages/makeabledk-laravel-eloquent-status/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (23)Used By (1)

Laravel Eloquent Status
=======================

[](#laravel-eloquent-status)

[![Latest Version on Packagist](https://camo.githubusercontent.com/bf764efedf42540c908b2c72822b545848ffcdbff9e6245c9a412320db3c2c57/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d616b6561626c65646b2f6c61726176656c2d656c6f7175656e742d7374617475732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/makeabledk/laravel-eloquent-status)[![Build Status](https://camo.githubusercontent.com/a4d5c92369e9e4f0843c4d334b66ccad09d42b41a6deb999e1f61822e712d0f6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6d616b6561626c65646b2f6c61726176656c2d656c6f7175656e742d7374617475732f52756e25323074657374733f6c6162656c3d5465737473)](https://github.com/makeabledk/laravel-eloquent-status/actions)[![StyleCI](https://camo.githubusercontent.com/db52a251f50676f0c01637704bfbbd07ae1a27c5f8c5485be56bcffbe84217a9/68747470733a2f2f7374796c6563692e696f2f7265706f732f3130323437343433332f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/102474433)

**Check out the blog post explaining the concepts of this package:**

---

Most models has some sort of status or state to it. Few examples could be

- Post: draft, private, published,
- Job: applied, accepted, declined, completed, cancelled
- Approval: pending, reviewing, approved

Traditionally you may find yourself having a `scopeAccepted` and then additionally a `ìsAccepted` helper method to test a model-instance against a specific status.

This package offers a very handy way of dealing with statuses like these without cluttering you model.

When you've successfully setup this package you'll be able to achieve syntax like

```
Approval::status('approved')->get(); // Collection
```

```
$model->checkStatus('approved'); // bool
```

---

Makeable is web- and mobile app agency located in Aarhus, Denmark.

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

[](#installation)

You can install this package via composer:

```
composer require makeabledk/laravel-eloquent-status
```

Example usage
-------------

[](#example-usage)

Given our Approval example from earlier we may have the following database fields:

- id
- *... (some foreign keys)*
- tutor\_approved\_at
- teacher\_approved\_at
- assessor\_approved\_at
- created\_at
- updated\_at

Let's start out by creating a status class that holds our status definitions

### Getting started

[](#getting-started)

#### 1. Create a status class

[](#1-create-a-status-class)

We will define all our valid statuses as public functions in a dedicated status class.

```
