News

Archive Eloquent Models with the “Archivable” Package

Published
Archive Eloquent Models with the “Archivable” Package image

The Laravel Archivable package by Joel Butcher is a simple package for making Eloquent models “archivable.” After adding the Archivable tait to your model(s), you have access to various macros:

$user = User::first();
 
// Archive a user
$user->archive();
// Remove user from the archive
$user->unArchive();
 
// Include archived users
$usersWithArchived = User::query()->withArchived();
 
// Only archived users
$onlyArchivedUsers = User::query()->onlyArchived();

Though the examples use the User model, this trait could be useful for things like a Ticket model or a Conversation model, or anywhere you have an archive feature to hide models from active model lists.

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

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 →
Securing Filament plugins with Plumb image

Securing Filament plugins with Plumb

Read article
LayaPHP: Self-Hosted Text Classification for PHP and Laravel image

LayaPHP: Self-Hosted Text Classification for PHP and Laravel

Read article
WhenMounted and BigInt Props in Inertia.js v3.8 image

WhenMounted and BigInt Props in Inertia.js v3.8

Read article
Postcodes for Laravel: GB Postcode Lookup and Geography Data image

Postcodes for Laravel: GB Postcode Lookup and Geography Data

Read article
Laravel 14 Adds a defaults() Method to Eloquent Models image

Laravel 14 Adds a defaults() Method to Eloquent Models

Read article
Laravel AI SDK and Laravel MCP Security Fixes: Update Now image

Laravel AI SDK and Laravel MCP Security Fixes: Update Now

Read article