Download the PHP package spatie/laravel-model-status without Composer

On this page you can find all versions of the php package spatie/laravel-model-status. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-model-status

Assign statuses to Eloquent models

Latest Version on Packagist GitHub Workflow Status Check & fix styling Total Downloads

Imagine you want to have an Eloquent model hold a status. It's easily solved by just adding a status field to that model and be done with it. But in case you need a history of status changes or need to store some extra info on why a status changed, just adding a single field won't cut it.

This package provides a HasStatuses trait that, once installed on a model, allows you to do things like this:

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

You must publish the migration with:

Migrate the statuses table:

Optionally you can publish the config-file with:

This is the contents of the file which will be published at config/model-status.php

Usage

Add the HasStatuses trait to a model you like to use statuses on.

Set a new status

You can set a new status like this:

A reason for the status change can be passed as a second argument.

Retrieving statuses

You can get the current status of model:

You can also get latest status of a given name:

Get all available status names for the model.

The following examples will return statusses of type status 1 or status 2, whichever is latest.

All associated statuses of a model can be retrieved like this:

This will check if the model has status:

Retrieving models with a given latest state

The currentStatus scope will return models that have a status with the given name.

Retrieving models without a given state

The otherCurrentStatus scope will return all models that do not have a status with the given name, including any model that does not have any statuses associated with them.

You can also provide an array of status names to exclude from the query.

Validating a status before setting it

You can add custom validation when setting a status by overwriting the isValidStatus method:

If isValidStatus returns false a Spatie\ModelStatus\Exceptions\InvalidStatus exception will be thrown.

You may bypass validation with the forceSetStatus method:

Check if status has been assigned

You can check if a specific status has been set on the model at any time by using the hasEverHadStatus method:

Check if status has never been assigned

You can check if a specific status has never been set on the model at any time by using the hasNeverHadStatus method:

Delete status from model

You can delete any given status that has been set on the model at any time by using the deleteStatus method:

Delete single status from model:

Delete multiple statuses from model at once:

Events

TheSpatie\ModelStatus\Events\StatusUpdated event will be dispatched when the status is updated.

Custom model and migration

You can change the model used by specifying a class name in the status_model key of the model-status config file.

You can change the column name used in the status table (model_id by default) when using a custom migration where you changed that. In that case, simply change the model_primary_key_attribute key of the model-status config file.

Testing

This package contains integration tests that are powered by orchestral/testbench.

You can run all tests with:

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you've found a bug regarding security please mail [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-model-status with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/support Version ^10.0|^11.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package spatie/laravel-model-status contains the following files

Loading the files please wait ....