Archive Eloquent Models with the “Archivable” Package
Published on by Paul Redmond
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.