Download the PHP package ritechoice23/laravel-saveable without Composer
On this page you can find all versions of the php package ritechoice23/laravel-saveable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ritechoice23/laravel-saveable
More information about ritechoice23/laravel-saveable
Files in ritechoice23/laravel-saveable
Package laravel-saveable
Short Description A flexible Laravel package for adding save/bookmark functionality to any model with collections, metadata, and ordering support.
License MIT
Homepage https://github.com/ritechoice23/laravel-saveable
Informations about the package laravel-saveable
Laravel Saveable
A flexible Laravel package for adding save/bookmark functionality to any Eloquent model with collections, metadata, and custom ordering support. Perfect for building features like bookmarks, favorites, reading lists, and more!
Features
- Fully Polymorphic: Any model can save any other model (User → Post, User → Article, etc.)
- MorphMap Compatible: Full support for both
Relation::morphMap()and base class path configurations - Collections/Folders: Organize saved items into nested collections
- Metadata Support: Add notes, priorities, or custom data to saves
- Custom Ordering: Control the order of saved items within collections
- Simple API: Intuitive methods like
saveItem(),unsaveItem(),toggleSaveItem(),hasSavedItem() - Rich Queries: Chainable query scopes and eager loading support
- Zero Configuration: Works out of the box with sensible defaults
- Full Test Coverage: Comprehensive Pest PHP test suite included
Table of Contents
- Installation
- Configuration
- Model Setup
- Basic Usage
- Collection Management
- Retrieving Saved Items
- Advanced Features
- API Reference
- Testing
Why This Package?
Popular Alternatives
- maize-tech/laravel-markable
- cybercog/laravel-love (bookmark feature)
What Makes This Package Unique
✅ Collections/Folders System - Nested collections for organizing saved items (reading lists, watch later, favorites)
✅ Order Management - Custom ordering within collections with order_column
✅ Metadata on Saves - Notes, priorities, custom data on each save
✅ Unsorted Items Management - Dedicated methods for items saved without a collection
✅ Mixed Models in Collections - Save different model types in the same collection
✅ Move Between Collections - moveSavedItem() for reorganizing saved items
Installation
Install the package via composer:
Publish and run the migrations:
Optionally, publish the config file:
Configuration
The published config file (config/saveable.php) includes:
Model Setup
Add the traits to your models to enable the "saver" and "saveable" functionality.
1. The "Saver" Model (e.g., User)
Add the HasSaves trait to any model that should be able to save things.
2. The "Saveable" Model (e.g., Post)
Add the IsSaveable trait to any model that you want to be saveable.
Basic Usage
Saving & Unsaving
All methods are called from the "saver" model (e.g., your User instance).
Save an item:
Unsave an item:
Toggle a save:
Check if an item is saved:
You can also check from the "saveable" model:
Count how many times an item has been saved:
Collection Management
Creating Collections
Collections are owned by a "saver" (typically a User).
Create a top-level collection:
Create a nested collection:
Saving to Collections
Pass the collection as the second argument to the saveItem method.
Retrieving Collections & Items
Get all collections for a user:
Get only top-level (root) collections:
Get a collection's children (sub-folders):
Get a collection's parent:
Get all saved items within a collection:
Move a saved item to a different collection:
Retrieving Saved Items
Get all "save" records for a user:
This returns the Save model instances, which include metadata.
Get all saved items as a query (single type):
This returns a Builder so you can chain additional queries.
Get saved items grouped by type:
Perfect for when users save multiple model types.
Get all unsorted items:
This gets items that were saved without a collection.
Get all users who saved a specific item:
Count saved items:
Advanced Features
Metadata
You can add extra data (like notes) to a save. This is stored in a JSON column on the saves table.
Save with metadata:
Update metadata on an existing save:
Retrieve metadata:
Ordering
The saves table has an order_column (integer). When a user saves an item, it's automatically given the next available number for its scope (user + collection).
You can retrieve items in this order:
Query Scopes
Eager load save counts:
Get most saved posts:
Check save status for current user:
Filter posts saved by a user:
Filter users who saved a specific post:
API Reference
HasSaves Trait Methods
| Method | Parameters | Return | Description |
|---|---|---|---|
saveItem() |
Model $model, ?Collection $collection, array $metadata |
bool |
Save an item with optional collection/metadata |
unsaveItem() |
Model $model |
bool |
Unsave an item |
toggleSaveItem() |
Model $model, ?Collection $collection, array $metadata |
bool |
Toggle save status |
hasSavedItem() |
Model $model |
bool |
Check if has saved a model |
getSavedRecord() |
Model $model |
?Save |
Get the save record for a model |
moveSavedItem() |
Model $model, ?Collection $collection |
bool |
Move a save to a different collection |
updateSavedItemMetadata() |
Model $model, array $metadata |
bool |
Update metadata on a save |
savedItems() |
?string $type |
Builder |
Get saved items query (chainable) |
savedItemsOfType() |
string $type |
Builder |
Get saved items of specific type |
savedItemsGrouped() |
- | Collection |
Get saved items grouped by type |
unsortedSavedRecords() |
- | Collection |
Get unsorted Save records |
unsortedSavedItems() |
?string $type |
Builder |
Get unsorted items query |
savedItemsCount() |
?string $type |
int |
Count saved items |
savedRecords() |
- | MorphMany |
Relationship: all Save records |
collections() |
- | HasMany |
Relationship: all collections owned |
rootCollections() |
- | HasMany |
Relationship: root collections |
HasSaves Trait Scopes
| Scope | Parameters | Description |
|---|---|---|
whereSavedItem() |
Model $model |
Filter by models that saved an item |
IsSaveable Trait Methods
| Method | Parameters | Return | Description |
|---|---|---|---|
timesSaved() |
- | int |
Total number of saves |
isSavedBy() |
Model $saver |
bool |
Check if saved by a specific model |
savedRecordBy() |
Model $saver |
?Save |
Get save record by a specific model |
savers() |
?string $type |
Builder |
Get savers query (chainable) |
saversGrouped() |
- | Collection |
Get savers grouped by type |
removeSavedBy() |
Model $saver |
bool |
Remove a specific model's save |
saversCount() |
?string $type |
int |
Count savers |
saveRecords() |
- | MorphMany |
Relationship: all Save records |
IsSaveable Trait Scopes
| Scope | Parameters | Description |
|---|---|---|
withSavesCount() |
- | Eager load save count |
mostSaved() |
int $limit = 10 |
Order by most saved |
withSaveStatus() |
Model $saver |
Add save status for a specific saver |
whereSavedBy() |
Model $saver |
Filter by saved by a saver |
Practical Examples
Building a Bookmark Feature
User's Saved Items Dashboard
Popular Posts
Get Saved Posts with Filtering
Testing
Run the test suite:
Run tests with coverage:
Run static analysis:
Run code formatting:
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Daramola Babatunde Ebenezer
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-saveable with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^11.0||^12.0