PHPackages                             laragear/expire-route - 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. [Caching](/categories/caching)
4. /
5. laragear/expire-route

ActiveLibrary[Caching](/categories/caching)

laragear/expire-route
=====================

Don't find route models created after a moment in time.

v3.0.0(2mo ago)24MITPHPPHP ^8.3CI passing

Since Aug 27Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/Laragear/ExpireRoute)[ Packagist](https://packagist.org/packages/laragear/expire-route)[ Fund](https://github.com/sponsors/DarkGhostHunter)[ Fund](https://paypal.me/darkghosthunter)[ RSS](/packages/laragear-expire-route/feed)WikiDiscussions 3.x Synced 1mo ago

READMEChangelog (4)Dependencies (8)Versions (8)Used By (0)

Expire Route
============

[](#expire-route)

[![Latest Version on Packagist](https://camo.githubusercontent.com/5970b057407be469cb1571abb7c9ae54fe344467b90e33e33b0002b7597e4807/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c617261676561722f6578706972652d726f7574652e737667)](https://packagist.org/packages/laragear/expire-route)[![Latest stable test run](https://github.com/Laragear/ExpireRoute/actions/workflows/php.yml/badge.svg?branch=1.x)](https://github.com/Laragear/ExpireRoute/actions/workflows/php.yml)[![Codecov Coverage](https://camo.githubusercontent.com/0ce0ab037dac1341a2462884742f6502a05c6067d40cb857cb3ff7de878e4240/68747470733a2f2f636f6465636f762e696f2f67682f4c617261676561722f457870697265526f7574652f67726170682f62616467652e7376673f746f6b656e3d6a52586c623555774366)](https://codecov.io/gh/Laragear/ExpireRoute)[![Maintainability](https://camo.githubusercontent.com/4b2168ad0504a612000c1cc879dfa9b4d9f8f894e5f7e9b0c87e1c4c72b2bb5e/68747470733a2f2f716c74792e73682f6261646765732f32643632326136642d633162332d346438372d386663632d3561376564643964616137622f6d61696e7461696e6162696c6974792e737667)](https://qlty.sh/gh/Laragear/projects/ExpireRoute)[![Sonarcloud Status](https://camo.githubusercontent.com/760fc01d46c27d5a5ca61ad8d7c6e328df034c2f37bd5e58357bd38a9713dae9/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d4c617261676561725f457870697265526f757465266d65747269633d616c6572745f737461747573)](https://sonarcloud.io/dashboard?id=Laragear_ExpireRoute)[![Laravel Octane Compatibility](https://camo.githubusercontent.com/70359a356da237cd29561bc5d0bb80baae775b5ff62f288ed324755382858342/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2532304f6374616e652d436f6d70617469626c652d737563636573733f7374796c653d666c6174266c6f676f3d6c61726176656c)](https://laravel.com/docs/11.x/octane#introduction)

Never found models or objects past their expiration time.

```
use Illuminate\Support\Facades\Route;
use App\Models\Payment;
use App\Models\Party;

Route::get('/payment/{payment}', function (Payment $payment) {
    // ...
})->middleware('expires');
```

Become a sponsor
----------------

[](#become-a-sponsor)

[![](.github/assets/support.png)](https://github.com/sponsors/DarkGhostHunter)

Your support allows me to keep this package free, up to date and maintainable. Alternatively, you can **[spread the word!](http://twitter.com/share?text=I%20am%20using%20this%20cool%20PHP%20package&url=https://github.com%2FLaragear%2FExpireRoute&hashtags=PHP,Laravel)**

Requirements
------------

[](#requirements)

- PHP 8.3 or later
- Laravel 12 or later

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

[](#installation)

Just fire up Composer and require the package in your application

```
composer require laragear/expire-route
```

Usage
-----

[](#usage)

While [Laravel Temporarily Protected Routes](https://laravel.com/docs/12.x/urls#signed-urls) works great for making routes available for a given amount of time, this library uses your Eloquent Model in the route to expire it through a middleware.

To better understand how the middleware works, let's imagine we have the `App\Models\Payment` model with an `expires_at` attribute that determines when the payment should be become invalid. The `expires` middleware does this automatically: if the `expires_at` time is past, the request will be aborted with a `HTTP 410 Gone` code.

```
use Illuminate\Support\Facades\Route;
use App\Models\Payment;

Route::get('payment/{payment}', function (Payment $invite) {
    // ...
})->middleware('expires');
```

### Multiple route parameters

[](#multiple-route-parameters)

By default, the middleware will always check for the **last route parameter** in a route. You may set the name of the parameter if you require to check its expiration time.

```
use Illuminate\Support\Facades\Route;
use App\Models\Payment;
use App\Models\Detail;

Route::get('payment/{payment}/detail/{detail}')
    ->uses(function (Payment $payment, Detail $detail) {
        // ...
    })
    ->middleware('expires:payment');
```

### Custom attribute

[](#custom-attribute)

If your model doesn't have an `expires_at` attribute to check, you can use `dot.notation` to traverse the object attributes and find the expiration time.

```
use Illuminate\Support\Facades\Route;
use App\Models\Payment;

Route::get('payment/{payment}', function (Payment $payment) {
    // ...
})->middleware('expires:payment.due_at');
```

### Relative expiration

[](#relative-expiration)

When you have a model that doesn't have an expiration time, you can set a time in minutes (or a string to be parsed by [`strtotime()`](https://www.php.net/manual/function.strtotime.php)) to calculate from the `created_at` attribute when the route should expire.

For example, by setting `60`, the route will expire once 60 minutes have passed since the creation of the `App\Models\Payment` model.

```
use Illuminate\Support\Facades\Route;
use App\Models\Payment;

Route::get('payment/{payment}', function (Payment $party) {
    // ...
})->middleware('expires:payment,60');
```

If you want to calculate the time from other attribute than `created_at`, issue the name of the attribute using `dot.notation`.

```
use Illuminate\Support\Facades\Route;
use App\Models\Payment;

Route::get('payment/{payment}', function (Payment $party) {
    // ...
})->middleware('expires:payment.issued_at,24 hours');
```

Warning

If the property or attribute doesn't exist or returns `null`, it will be assumed the model has **not** expired yet.

### Using the `routeExpiresAt()` method

[](#using-the-routeexpiresat-method)

If the model or object implements the `Laragear\ExpireRoute\Contracts\RouteExpirable` contract, the `routeExpiresAt()` method will be used to retrieve the moment the route it should expire.

```
namespace App\Models;

use DateTimeInterface;
use Illuminate\Database\Eloquent\Model;
use Laragear\ExpireRoute\Contracts\RouteExpirable;

class Payment extends Model implements RouteExpirable
{
    // ...

    public function routeExpiresAt(): DateTimeInterface
    {
        return $this->created_at->addMinutes(60);
    }
}
```

Important

Using the contract **takes precedence**, unless an attribute is specified by the middleware declaration itself.

Non Eloquent Models
-------------------

[](#non-eloquent-models)

Both middlewares are not limited to only Eloquent Models. It can be any object (even an array) that has a UNIX Epoch timestamp or a datetime, since the check is done by retrieving the value through [`data_get()`](https://laravel.com/docs/11.x/helpers#method-data-get) and then parsed by Laravel's Date Factory.

```
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\Route;

class Thing
{
    public function __construct(public $expiredAt)
    {
        //
    }
}

Route::bind('thing', fn($time = 'now') => new Thing($value));

Route::get('some/{thing}', function (Thing $thing) {
    // ...
})->middleware('expires:thing.expiredAt');
```

Fluent middleware declaration
-----------------------------

[](#fluent-middleware-declaration)

You may also use the `Laragear\ExpireRoute\Http\Middleware\Expires` middleware to fluently configure it in your route. It's a great way to set relative time expressively.

```
use Illuminate\Support\Facades\Route;
use Laragear\ExpireRoute\Http\Middleware\Expires;

// Set the parameter name and attribute
Route::get('/payment/{payment}/details/{detail}')
    ->middleware(Expires::using('payment.expiration_time'));

// Set the relative amount of time to check.
Route::get('/payment/{payment}')
    ->middleware(Expires::in(1)->hour()->and(30)->minutes());

// Set the relative amount of time to check.
Route::get('/payment/{payment}')
    ->middleware(Expires::after('60 minutes');
```

Laravel Octane compatibility
----------------------------

[](#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
--------

[](#security)

If you discover any security-related issues, please email  instead of using the issue tracker.

License
=======

[](#license)

This specific package version is licensed under the terms of the [MIT License](LICENSE.md), at the time of publishing.

[Laravel](https://laravel.com) is a Trademark of [Taylor Otwell](https://github.com/TaylorOtwell/). Copyright © 2011–2026 Laravel LLC.

###  Health Score

44

—

FairBetter than 91% of packages

Maintenance94

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~93 days

Recently: every ~101 days

Total

7

Last Release

62d ago

Major Versions

v1.0.1 → v2.0.02025-03-29

2.x-dev → 3.x-dev2026-03-08

PHP version history (3 changes)v1.0.0PHP ^8.1

v2.0.0PHP ^8.2

3.x-devPHP ^8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5141911?v=4)[Italo](/maintainers/DarkGhostHunter)[@DarkGhostHunter](https://github.com/DarkGhostHunter)

---

Top Contributors

[![DarkGhostHunter](https://avatars.githubusercontent.com/u/5141911?v=4)](https://github.com/DarkGhostHunter "DarkGhostHunter (9 commits)")

---

Tags

cacheexpirationexpirehidelaravelphp

### Embed Badge

![Health badge](/badges/laragear-expire-route/health.svg)

```
[![Health](https://phpackages.com/badges/laragear-expire-route/health.svg)](https://phpackages.com/packages/laragear-expire-route)
```

###  Alternatives

[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k8.2M51](/packages/spatie-laravel-responsecache)[genealabs/laravel-model-caching

Automatic caching for Eloquent models.

2.4k4.8M26](/packages/genealabs-laravel-model-caching)[mikebronner/laravel-model-caching

Automatic caching for Eloquent models.

2.4k127.1k1](/packages/mikebronner-laravel-model-caching)[intervention/image-laravel

Laravel Integration of Intervention Image

1496.5M100](/packages/intervention-image-laravel)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[konekt/html

HTML and Form Builders for the Laravel Framework

24403.2k5](/packages/konekt-html)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
