Download the PHP package digikraaft/laravel-model-suspension without Composer

On this page you can find all versions of the php package digikraaft/laravel-model-suspension. 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-suspension

Suspend Eloquent models

tests Build Status Scrutinizer Code Quality Code Intelligence Status License: MIT

Imagine you want to suspend an Eloquent model, a User model for example. Usually, adding an is_suspended field to the model could work. But then you can't keep track of why the model was suspended, how many times or even set the duration of the suspension.

This package provides a CanBeSuspended trait that enables you do all of these, once installed. It would be something like this:

Installation

You can install the package via composer:

You must publish the migration with:

Run the migration to publish the suspensions table with:

You can optionally publish the config-file with:

The content of the file that will be published to config/model-suspension.php:

Usage

Add the CanBeSuspended trait to the model you would like to suspend:

Suspend model

You can suspend a model like this:

The number of days to be suspended for with a reason can be passed as the first and second arguments respectively:

You can also specify the suspension period (in minutes or days) with an optional third argument:

Retrieving suspensions

You can get the current suspension of the model like this:

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

The allSuspensions scope can be used to retrieve all the suspensions of the model:

The activeSuspensions scope can be used to retrieve only active suspensions:

The nonActiveSuspensions scope can be used to retrieve only non-active suspensions:

Get number of times a model has been suspended

You can get the number of times a model has been suspended like this:

To get the number of times a model has been suspended over a period, pass in a Carbon formatted $from and $to dates as the first and second arguments respectively:

Note that an InvalidDate exception will be thrown if the $from date is later than the $to

Check if model has been suspended

You can check if a model is currently suspended:

You can also check if a model has ever been suspended:

Unsuspend model

You can unsuspend a model at any time by using the unsuspend method:

This will unsuspend the model immediately. If a suspension period has been initially specified, it will be overridden.

Events

The Digikraaft\ModelSuspension\Events\ModelSuspensionChanged event will be dispatched when a model is suspended or unsuspended.

Custom model and migration

You can change the model used by specifying a different class name in the suspension_model key of the model-suspension config file.

You can also change the column name used in the suspension table (default is model_id) when using a custom migration. If this is the case, also change the model_primary_key_attribute key of the model-suspension config file.

Testing

Use the command below to run your tests:

More Good Stuff

Check here for more awesome free stuff!

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [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-suspension with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
laravel/framework 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 digikraaft/laravel-model-suspension contains the following files

Loading the files please wait ....