{"id":33980496,"url":"https://github.com/eazyserver/laravel-expirable","last_synced_at":"2025-12-13T03:03:41.502Z","repository":{"id":57086134,"uuid":"83989503","full_name":"EazyServer/laravel-expirable","owner":"EazyServer","description":"This package simplify adding expirable feature to any eloquent model on your Laravel project.","archived":false,"fork":false,"pushed_at":"2017-03-25T18:32:56.000Z","size":8,"stargazers_count":9,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-19T20:48:37.550Z","etag":null,"topics":["eloquent-models","expired-models","expiry","laravel","laravel-expirable","trait"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EazyServer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-05T17:41:48.000Z","updated_at":"2020-07-20T11:58:16.000Z","dependencies_parsed_at":"2022-08-25T00:50:33.276Z","dependency_job_id":null,"html_url":"https://github.com/EazyServer/laravel-expirable","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/EazyServer/laravel-expirable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EazyServer%2Flaravel-expirable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EazyServer%2Flaravel-expirable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EazyServer%2Flaravel-expirable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EazyServer%2Flaravel-expirable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EazyServer","download_url":"https://codeload.github.com/EazyServer/laravel-expirable/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EazyServer%2Flaravel-expirable/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27699235,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-13T02:00:09.769Z","response_time":147,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["eloquent-models","expired-models","expiry","laravel","laravel-expirable","trait"],"created_at":"2025-12-13T03:03:37.828Z","updated_at":"2025-12-13T03:03:41.495Z","avatar_url":"https://github.com/EazyServer.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Expirable\n\nAdd expiring feature to Eloquent models in Laravel 5.\n\n\n## Background\n\nThis has been developed to simplify adding `expirable` feature to any eloquent model on your laravel project. \n\n\n## Installation\nTo install the package via Composer:\n\n```shell\n$ composer require yarob/laravel-expirable\n```\nThen, update `config/app.php` by adding an entry for the service provider.\n\n```php\n'providers' =\u003e [\n    // ...\n    Yarob\\LaravelExpirable\\ServiceProvider::class,\n];\n```\nFinally, via terminal, publish the default configuration file (if you need to, see below):\n\n```shell\nphp artisan vendor:publish --provider=\"Yarob\\LaravelExpirable\\ServiceProvider\"\n```\n## Updating your Eloquent Models\n\nYour models can now use the `Expirable` trait.\nYou must also add `expire_at` to your `$dates` array in the model as shown in the example below\n\n```php\nuse Yarob\\LaravelExpirable\\Expirable;\n\nclass User extends Model\n{\n    use Expirable;\n    \n    /**\n     * The attributes that should be mutated to dates.\n     *\n     * @var array\n     */\n    protected $dates = [\n        'expire_at'\n    ];\n\n}\n```\n\n## Migration\nYour model MUST have column named `expire_at` in the database to store the expiry date value.\nYou can add this manually via a migration on the intended model ` $table-\u003etimestamp('expire_at')-\u003enullable(); `. \n\n## Usage\n\nThere are three basic functions in `Expirable` trait:\n* `hasExpired()` to check if model has expired or not returns `boolean`\n* `timeToLive()` returns number of seconds left on models life, could be minus if has expired already! returns `false` if not applicable.\n* `reviveExpired($numberOfSeconds=null)` if model has expired you can then revive it by using this function and supplying `$numberOfSeconds` revival period starting from `now()`. If `$numberOfSeconds` is not supplied then will default back to the value set in `expirable.php` in config folder, if set! Otherwise it will not do anything and returns `false`.\n* Model has `null` expiry date means a non-expirable model and lives forever, e.g. `$user-\u003eexpire_at = null;`\n \n Example:-\n\n```php\n$user = App\\User::get();\n\nforeach($users as $user) {\n\t\tif($user-\u003ehasExpired())\n\t\t{\n\t\t\tvar_dump($user-\u003etimeToLive());\n\t\t\t$user-\u003ereviveExpired();\n\t\t\t\n\t\t\tvar_dump($user-\u003etimeToLive());\t\n\t\t}\n\t\telse\n\t\t{\n\t\t    $user-\u003eexpire_at = \\Carbon\\Carbon::now()-\u003eaddDay(-10);// you can add minus values\n            $user-\u003esave();\n                        \n            var_dump($user-\u003etimeToLive());\t\n\t\t}\n\t}\n```\n\n## Querying Expirable Models\nExpired models (passed it’s expiry date) will automatically be excluded from query results. \nFor example:-\n```php\n $users = App\\User::get();\n```\nwill only gets models that has NOT expired or has `null` expiry date. Any expired models WILL be auto-excluded.\n\n\n### Including expired Models\n\nYou can force expired models to appear in query results using `withHasExpiry`\n\n```php\n$users = App\\User::withHasExpiry()-\u003eget();\n```\n\n### Retrieving Only Expired Models\n  \nThe `onlyHasExpiry` method can be used on a relationship query:\n\n```php\n$users = App\\User::onlyHasExpiry()-\u003eget();\n```\nThis will exclude ONLY `null` expiry date from results.\nPlease note this will get ALL models that have non `null` expiry date, regradless of their expiry date.\n\n### Retrieving Models has `null` expiry\n  \nThe `withoutHasExpiry` method can be used in this case:\n\n```php\n$users = App\\User::withoutHasExpiry()-\u003eget();\n```\n\nThis will bring models that has `null` expiry date.\n\n## Configuration\n\nConfiguration is not usually needed, unless you want to set a default revival time to a model(s). A default value of `86400 seconds` is set for user model, as an example, but feel free to change that to any value you want.\nHere is an example configuration:\n\n```php\nreturn [\n\n\t/**\n\t * Revival Time in seconds used to extend life in expired models\n\t */\n\n\t'User' =\u003e [\n\t\t'revival_time' =\u003e 24*60*60,\n\t]\n];\n```\n\nPay attention that Model name in `expirable.php` is case sensitive! so if you have a `foo` Model, then\n\n```php\nreturn [\n    'foo' =\u003e [\n    \t\t'revival_time' =\u003e 24*60*60,\n    \t],\n];\n```\n\n## Copyright and License\n\n[laravel-expirable](https://github.com/EazyServer/laravel-expirable) was written by [Yarob Al-Taay](https://twitter.com/TheEpicVoyage) and is released under the \n[MIT License](LICENSE.md).\n\nCopyright (c) 2017 Yarob Al-Taay","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feazyserver%2Flaravel-expirable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feazyserver%2Flaravel-expirable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feazyserver%2Flaravel-expirable/lists"}