PHPackages                             andrey-helldar/last-modified - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. andrey-helldar/last-modified

Abandoned → [dragon-code/last-modified](/?search=dragon-code%2Flast-modified)Library[HTTP &amp; Networking](/categories/http)

andrey-helldar/last-modified
============================

Setting the response code 304 Not Modified in the absence of content changes.

4.4.0(1mo ago)86.6kMITPHPPHP ^8.0CI passing

Since Jan 24Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/TheDragonCode/last-modified)[ Packagist](https://packagist.org/packages/andrey-helldar/last-modified)[ Fund](https://boosty.to/dragon-code)[ Fund](https://yoomoney.ru/to/410012608840929)[ RSS](/packages/andrey-helldar-last-modified/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (10)Dependencies (26)Versions (51)Used By (0)

Last Modified
=============

[](#last-modified)

  ![Last Modified](https://camo.githubusercontent.com/4255b1e49b252f04d63c8ab44548b874f304aba3190e0852c1eab8828c123b15/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c6173742532304d6f6469666965642e706e673f7061747465726e3d746f706f677261706879267374796c653d7374796c655f3226666f6e7453697a653d3130307078266d643d312673686f7757617465726d61726b3d31267468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d647261676f6e2d636f64652532466c6173742d6d6f646966696564266465736372697074696f6e3d53657474696e672b7468652b726573706f6e73652b636f64652b3330342b4e6f742b4d6f6469666965642b696e2b7468652b616273656e63652b6f662b636f6e74656e742b6368616e6765732e26696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)Last Modified for Laravel
-------------------------

[](#last-modified-for-laravel)

[![last modified](https://camo.githubusercontent.com/c3a50791df622b405f6f3a94af149088e0703aa4b7625ac721ddcbf974b9fbaa/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c6173742532304d6f6469666965642e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d647261676f6e2d636f64652532466c6173742d6d6f646966696564267061747465726e3d746f706f677261706879267374796c653d7374796c655f32266465736372697074696f6e3d62792b5468652b447261676f6e2b436f6465266d643d312673686f7757617465726d61726b3d3126666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)](https://camo.githubusercontent.com/c3a50791df622b405f6f3a94af149088e0703aa4b7625ac721ddcbf974b9fbaa/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c6173742532304d6f6469666965642e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d647261676f6e2d636f64652532466c6173742d6d6f646966696564267061747465726e3d746f706f677261706879267374796c653d7374796c655f32266465736372697074696f6e3d62792b5468652b447261676f6e2b436f6465266d643d312673686f7757617465726d61726b3d3126666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)

[![Stable Version](https://camo.githubusercontent.com/f67590ea89a5fab3d89d44cbd6eb9859cc000a415dd0ff522dbaaed48b50f99b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f546865447261676f6e436f64652f6c6173742d6d6f6469666965643f6c6162656c3d737461626c65267374796c653d666c61742d737175617265)](https://packagist.org/packages/dragon-code/last-modified)[![Total Downloads](https://camo.githubusercontent.com/49523399a95189960fa7f021bc8614c1f3cb6f70ce633eb384056e02bf79aa50/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f647261676f6e2d636f64652f6c6173742d6d6f6469666965642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dragon-code/last-modified)[![Github Workflow Status](https://camo.githubusercontent.com/1c703e3e1683e862e364415434a372d0189fe65e546fcda243061f23229fed27/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f546865447261676f6e436f64652f6c6173742d6d6f6469666965642f706870756e69742e796d6c3f7374796c653d666c61742d737175617265)](https://github.com/TheDragonCode/last-modified/actions)[![License](https://camo.githubusercontent.com/eb9e1fd5c6283b47106fc990fdd435ad20d4a2b7a4cca9fc6125642d14822eba/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f647261676f6e2d636f64652f6c6173742d6d6f6469666965642e7376673f7374796c653d666c61742d737175617265)](LICENSE)

> Setting the response code 304 Not Modified in the absence of content changes.

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

[](#installation)

To get the latest version of `Last Modified` simply require the project using [Composer](https://getcomposer.org):

```
$ composer require dragon-code/last-modified
```

Instead, you may of course manually update your require block and run `composer update` if you so choose:

```
{
    "require": {
        "dragon-code/last-modified": "^4.0"
    }
}
```

And call `php artisan vendor:publish --provider="DragonCode\LastModified\ServiceProvider"` command.

> Note
>
> If you were using version 2.0 or less, run the `php artisan migrate` command. If this is your first time here, then you do not need to install this command, since, starting from version [2.1](https://github.com/TheDragonCode/last-modified/releases/tag/v2.1.0), we refused to store data in the database, replacing the storage with a cache.

Next, add middleware in `$middlewareGroups > web` section in `app/Http/Kernel.php` file:

```
use DragonCode\LastModified\Middlewares\CheckLastModified;

protected $middlewareGroups = [
    'web' => [
         CheckLastModified::class,
    ]
]
```

**IMPORTANT!** It's recommended to add a middleware after `CheckForMaintenanceMode::class`.

The system works like this: when opening a page, the middleware checks if there is an entry in the database table about this link. If there is, it checks the `Last-Modified` header key and returns either 200 or 304 code.

To add records to the table, it is recommended to create a console command in your application using the following example:

Create / Update
---------------

[](#create--update)

```
use Carbon\Carbon;
use DragonCode\LastModified\Resources\Item;
use DragonCode\LastModified\Services\LastModified;

public function handle()
{
    $collection_1 = Foo::whereIsActive(true)->get();
    $collection_2 = Bar::where('id', '>', 50)->get();
    $collection_3 = Baz::query()->get();

    $builder_1 = Foo::whereIsActive(true);
    $builder_2 = Bar::where('id', '>', 50);
    $builder_3 = Baz::query();

    $model_1 = Foo::whereIsActive(true)->first();
    $model_2 = Bar::where('id', '>', 50)->first();
    $model_3 = Baz::query()->first();

    $item_1 = Item::make(['url' => 'https://example.com/foo',      'updated_at' => Carbon::now());
    $item_2 = Item::make(['url' => 'https://example.com/bar',      'updated_at' => Carbon::parse('2018-03-02'));
    $item_3 = Item::make(['url' => 'https://example.com/baz?id=1', 'updated_at' => Carbon::now());

    LastModified::make()
        ->collections($collection_1, $collection_2, $collection_3)
        ->builders($builder_1, $builder_2, $builder_3)
        ->models($model_1, $model_2, $model_3)
        ->manual($item_1, $item_2, $item_3)
        ->update();
}
```

**IMPORTANT!** The `url` attribute must be available for models.

If the model has no attribute `url`, it should be created.

For example:

```
protected getUrlAttribute(): string
{
    $slug = $this->slug;

    return route('page.show', compact('slug'));
}
```

Delete
------

[](#delete)

```
use Carbon\Carbon;
use DragonCode\LastModified\Resources\Item;
use DragonCode\LastModified\Services\LastModified;

public function handle()
{
    $collection_1 = Foo::whereIsActive(false)->get();
    $collection_2 = Bar::whereIn('id', [50, 60, 62, 73])->get();

    $builder_1 = Foo::whereIsActive(true);
    $builder_2 = Bar::where('id', '>', 50);
    $builder_3 = Baz::query();

    $model_1 = Foo::whereIsActive(false)->first();
    $model_2 = Bar::whereIn('id', [50, 60, 62, 73])->first();

    $item_1 = Item::make(['url' => 'https://example.com/foo', 'updated_at' => Carbon::now()]);
    $item_2 = Item::make(['url' => 'https://example.com/bar', 'updated_at' => Carbon::now()]);

    LastModified::make()
        ->collections($collection_1, $collection_2, $collection_3)
        ->builders($builder_1, $builder_2, $builder_3)
        ->models($model_1, $model_2, $model_3)
        ->manual($item_1, $item_2, $item_3)
        ->delete();
}
```

Observer
--------

[](#observer)

In order to reduce the load on the database and free up the crown queue, it is recommended to use the observer to update the records:

```
namespace App\Observers;

use Illuminate\Database\Eloquent\Model;
use DragonCode\LastModified\Services\LastModified;

class LastModifiedObserver
{
    public function saving(Model $model)
    {
        LastModified::make()
            ->models($model)
            ->update();
    }

    public function deleting(Model $model)
    {
        LastModified::make()
            ->models($model)
            ->delete();
    }
}
```

Don't forget to add the link to the service provider:

```
namespace App\Providers;

use App\Observers\LastModifiedObserver;
use Illuminate\Foundation\Auth\User;
use Illuminate\Support\ServiceProvider;

class ObserverServiceProvider extends ServiceProvider
{
    public function boot()
    {
        Page::observe(LastModifiedObserver::class);
        News::observe(LastModifiedObserver::class);

        // ...
    }
}
```

License
-------

[](#license)

This package is licensed under the [MIT License](LICENSE).

###  Health Score

55

—

FairBetter than 98% of packages

Maintenance89

Actively maintained with recent releases

Popularity25

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity79

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~60 days

Recently: every ~282 days

Total

44

Last Release

55d ago

Major Versions

v1.9.1 → v2.0.02021-11-11

2.x-dev → 3.x-dev2022-02-15

v3.0.0 → v4.0.02022-04-21

PHP version history (5 changes)v1.0.0PHP ^7.1.3

v1.8.0PHP ^7.1.3|^8.0

v2.0.0PHP ^7.3|^8.0

v2.2.0PHP ^7.3 || ^8.0

v4.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/b77790e612f1c9beed1e1533e36eba4954fbd6da2a5c9f71e845cd0f5465f0ad?d=identicon)[Helldar](/maintainers/Helldar)

---

Top Contributors

[![andrey-helldar](https://avatars.githubusercontent.com/u/10347617?v=4)](https://github.com/andrey-helldar "andrey-helldar (42 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (34 commits)")[![actions-user](https://avatars.githubusercontent.com/u/65916846?v=4)](https://github.com/actions-user "actions-user (27 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (4 commits)")

---

Tags

304laravellast-modifiedphpheadersseodragondragon code304Last-Modifiednot-modified304-http-code

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/andrey-helldar-last-modified/health.svg)

```
[![Health](https://phpackages.com/badges/andrey-helldar-last-modified/health.svg)](https://phpackages.com/packages/andrey-helldar-last-modified)
```

###  Alternatives

[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k25.9M107](/packages/laravel-cashier)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[dragon-code/laravel-http-logger

Logging incoming HTTP requests

319.8k3](/packages/dragon-code-laravel-http-logger)[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[flarum/core

Delightfully simple forum software.

211.3M1.9k](/packages/flarum-core)[dragon-code/migrate-db

Easy data transfer from one database to another

15717.4k](/packages/dragon-code-migrate-db)

PHPackages © 2026

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