Download the PHP package laragear/expire-route without Composer
On this page you can find all versions of the php package laragear/expire-route. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download laragear/expire-route
More information about laragear/expire-route
Files in laragear/expire-route
Package expire-route
Short Description Don't find route models created after a moment in time.
License MIT
Informations about the package expire-route
Expire Route
Never found models or objects past their expiration time.
Become a sponsor
Your support allows me to keep this package free, up-to-date and maintainable. Alternatively, you can spread the word!
Usage
The expires
middleware looks for the expired_at
attribute or property for last route parameter. Once found, it checks if the current time is below the value.
If you have multiple route parameters, and you don't want to make the check against the last route parameter, prepend the name of the parameter to the middleware arguments.
By setting the route parameter, you can use dot.notation
to traverse the object and find the expiration time if it's not the default expired_at
.
If your model doesn't have an expiration time, but you want to calculate the expiration time from another attribute, like the created_at
, you may issue a second argument as an expiration time.
If you issue a number, it will be used as the amount of minutes. Any other string will be parsed by strtotime()
.
[!WARNING]
If the property or attribute doesn't exist or returns
null
, it will be assumed the model has not expired yet.
Non Eloquent Models
Both middlewares are not limited to only Eloquent Models. It can be any object (even an array) that has a timestamp or a datetime, since the check is done by retrieving the value through data_get()
and then parsed by Laravel's Date Factory.
Fluent middleware declaration
You may also use the Expire
middleware to fluently configure it. It's a great way to set relative time expressively.
Laravel Octane compatibility
- There are no singletons using a stale application instance.
- There are no singletons using a stale config instance.
- There are no singletons using a stale request instance.
- There are no static properties written during a request.
There should be no problems using this package with Laravel Octane.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
License
This specific package version is licensed under the terms of the MIT License, at time of publishing.
Laravel is a Trademark of Taylor Otwell. Copyright © 2011-2024 Laravel LLC.