PHPackages                             maize-tech/laravel-model-expires - 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. maize-tech/laravel-model-expires

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

maize-tech/laravel-model-expires
================================

Laravel Model Expires

1.1.0(2y ago)237822[4 PRs](https://github.com/maize-tech/laravel-model-expires/pulls)MITPHPPHP ^8.1CI passing

Since Nov 9Pushed 1mo ago5 watchersCompare

[ Source](https://github.com/maize-tech/laravel-model-expires)[ Packagist](https://packagist.org/packages/maize-tech/laravel-model-expires)[ Docs](https://github.com/maize-tech/laravel-model-expires)[ RSS](/packages/maize-tech-laravel-model-expires/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (16)Versions (7)Used By (0)

   ![Social Card of Laravel Model Expires](/art/socialcard-light.png)

Laravel Model Expires
=====================

[](#laravel-model-expires)

[![Latest Version on Packagist](https://camo.githubusercontent.com/dfef0fa21008b30a0bba887fb34aeed44453557b146246f8cc171bf5c93f8c1e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d61697a652d746563682f6c61726176656c2d6d6f64656c2d657870697265732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/maize-tech/laravel-model-expires)[![GitHub Tests Action Status](https://camo.githubusercontent.com/763bdc26ac7a83da19d01345c68726e832ef8736f8706939d4b1be214c58e17c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d61697a652d746563682f6c61726176656c2d6d6f64656c2d657870697265732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/maize-tech/laravel-model-expires/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/ccd516fe8d4058e043e7b9d016f008730a54d105344a94b5635ee1d6cb57aea3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d61697a652d746563682f6c61726176656c2d6d6f64656c2d657870697265732f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/maize-tech/laravel-model-expires/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/d57583588d1ee72b69952ed72294d76b7a6cd392cbafa17629556d468b5deab6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d61697a652d746563682f6c61726176656c2d6d6f64656c2d657870697265732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/maize-tech/laravel-model-expires)

With this package you can add expiration date to any model and exclude expired models from queries. When needed, you could send a notification for expiring models. You can also set a deletion date for every model and automatically clean them up with a command.

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

[](#installation)

You can install the package via composer:

```
composer require maize-tech/laravel-model-expires
```

You can publish the config and migration files and run the migrations with:

```
php artisan model-expires:install
```

This is the contents of the published config file:

```
return [

    /*
    |--------------------------------------------------------------------------
    | Expiration model
    |--------------------------------------------------------------------------
    |
    | Here you may specify the fully qualified class name of the expiration model.
    |
    */

    'expiration_model' => Maize\ModelExpires\Models\Expiration::class,

    'model' => [

        /*
        |--------------------------------------------------------------------------
        | Expires after days
        |--------------------------------------------------------------------------
        |
        | Here you may specify the default amount of days after which a model
        | should expire.
        | If null, all newly created models won't have a default expiration date.
        |
        */

        'expires_after_days' => null,

        /*
        |--------------------------------------------------------------------------
        | Deletes after days
        |--------------------------------------------------------------------------
        |
        | Here you may specify the default amount of days after which a model
        | should be deleted.
        | If null, all newly created models won't have a default deletion date.
        |
        */

        'deletes_after_days' => null,
    ],

    'expiring_notification' => [

        /*
        |--------------------------------------------------------------------------
        | Enable expiring notification
        |--------------------------------------------------------------------------
        |
        | Here you may specify whether you want to enable model expiring
        | notifications or not.
        |
        */

        'enabled' => true,

        /*
        |--------------------------------------------------------------------------
        | Notification class
        |--------------------------------------------------------------------------
        |
        | Here you may specify the fully qualified class name of the default notification.
        | If null, no notifications will be sent.
        |
        */

        'notification' => Maize\ModelExpires\Notifications\ModelExpiringNotification::class,

        /*
        |--------------------------------------------------------------------------
        | Notifiable emails
        |--------------------------------------------------------------------------
        |
        | Here you may specify the default list of notifiable email addresses.
        |
        */

        'notifiables' => [
            //
        ],
    ],
];
```

Usage
-----

[](#usage)

### Basic

[](#basic)

To use the package, add the `Maize\ModelExpires\HasExpiration` trait to all models you want to have an expiration date:

```
