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

acquaintsoft logo
Acquaint Softtech

Hire Laravel developers with AI expertise at $20/hr. Get started in 48 hours.

Visit Acquaint Softtech

The latest

View all →
Building EasyReply: How We Used Laravel to Unify Customer Support image

Building EasyReply: How We Used Laravel to Unify Customer Support

Read article
PostgreSQL Monitoring and Schema Linting for Laravel with Vacuum image

PostgreSQL Monitoring and Schema Linting for Laravel with Vacuum

Read article
PayZephyr: One Payment API for Stripe, Paystack, and PayPal image

PayZephyr: One Payment API for Stripe, Paystack, and PayPal

Read article
Bifrost Turns One With AI Builds and New Workflows image

Bifrost Turns One With AI Builds and New Workflows

Read article
Preview Blade Templates in macOS Finder with Quick Blade image

Preview Blade Templates in macOS Finder with Quick Blade

Read article
Artisan Debugging Commands in Laravel Telescope 5.24.0 image

Artisan Debugging Commands in Laravel Telescope 5.24.0

Read article