News

Assign Expiration Dates to Eloquent Models

Published
Assign Expiration Dates to Eloquent Models image

Laravel Model Expires is a package by Mark van den Broek that assigns expiration dates to models and gives you some conveniences for working with them. The package provides a convenient trait to make your models “expirable” in a snap:

namespace App\Models;
 
use Illuminate\Database\Eloquent\Model;
use Mvdnbrk\EloquentExpirable\Expirable;
 
class Subscription extends Model
{
use Expirable;
}

You’ll also need to set up an expires_at field to the model’s database table, which is easy using the package’s helper in your migrations:

Schema::create('subscriptions', function (Blueprint $table) {
$table->expires();
});

The expires_at column is cast to a Carbon instance, and you can also customize the name of the column if you desire in your model.

You’ll want to refer to the package’s documentation for full details of configuration, setting expiration dates, and working with models. Here are a few examples of methods provided to “expirable” models:

// Already has expired?
$subscription->expired()
 
// Will expire in the future?
$subscription->willExpire()
 
// Only get expired models
$subscriptions = Subscription::onlyExpired()->get();
 
// Models expiring in the future
$subscriptions = Subscription::expiring()->get();

You can learn more about this package, get full installation instructions, and view the source code on GitHub at mvdnbrk/laravel-model-expires.


This package was submitted to our Laravel News Links section. Links is a place the community can post packages and tutorials around the Laravel ecosystem. Follow along on Twitter @LaravelLinks

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Filed in

Sponsored

laravelcloud logo
Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Visit Laravel Cloud

The latest

View all →
Image Dominant Color and HEIC Support in Laravel 13.24 image

Image Dominant Color and HEIC Support in Laravel 13.24

Read article
Official Laravel Zed Extension: LSP for PHP & Blade image

Official Laravel Zed Extension: LSP for PHP & Blade

Read article
Laravel Head: Manage Meta Tags, Open Graph, and JSON-LD image

Laravel Head: Manage Meta Tags, Open Graph, and JSON-LD

Read article
PhpStorm 2026.2 Released image

PhpStorm 2026.2 Released

Read article
Laravel Doctor: Diagnose Your App With One Artisan Command image

Laravel Doctor: Diagnose Your App With One Artisan Command

Read article
CPX: The Composer Package Executor for PHP image

CPX: The Composer Package Executor for PHP

Read article