Download the PHP package javcorreia/laravel-wishlist without Composer
On this page you can find all versions of the php package javcorreia/laravel-wishlist. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download javcorreia/laravel-wishlist
More information about javcorreia/laravel-wishlist
Files in javcorreia/laravel-wishlist
Informations about the package laravel-wishlist
laravel-wishlist
A simple Wishlist implementation for Laravel 5.8|6.*|7.*|8.*|9.*|10.*
If you have problems with the minimum PHP version of 8.0: install previous stable version 2.2
This is a fork of the excellent Bhavinjr's laravel-wishlist.
I've added the possibility to save a wishlist associated with a custom session id, instead of just a user_id, making it more flexible.
It's also possible to extend the default Model wishlist model to add soft deletes possibility, if needed.
Hence, the table was changed a bit, as well as the methods.
Installation
Is installed via Composer by running in your project's root.
Publish the default configuration file:
Before running migration, edit the required settings using the resulting config/wishlist.php
file (See Configuration).
To create the table run migrations:
Configuration
Configuration was designed to be as flexible as changing the global configuration in the config/wishlist.php
file.
You will need to provide at least, the model for the items to be wishlisted, for example:
The other values can be the default ones, unless changes are needed.
After updating the config/wishlist.php
file execute the following command to cache configs:
Extending the Base Model to extra functionalities
If needed you can create a Model file, extend the base Wishlist model to add extra functionalities.
In the following example, we'll add the SoftDeletes
trait to have soft deletes in the wishlist table.
Create a migration to add soft delete functionality to the wishlist table
In the migration:
Run migrate to update table:
Extend the base model
Create the model:
Add the SoftDeletes
trait:
Change config to use your new Model class
In wishlist.php
config file:
Usage
Just use the provided facade to access its methods.
Hint: use Laravel IDE Helper Generator to have code completion on facade methods
The package gives you the following methods to use:
Adding an item to the wishlist is really simple
you need specify the item to add and the user to add it to respectively.
These two parameters are required.
type ['user', 'session'] is an optional parameter which tells the service if the user is an application authenticated user_id or
a custom session/cookie id.
Wishlist::add(item, user[, type='user'])
Wishlist::remove(id, user[, type='user'])
To remove an item from the wishlist, specify the wishlist_id and the user associated with the item.
type ['user', 'session'] is an optional parameter wich tells the service if the user is an application authenticated user_id or
a custom session/cookie id.
Wishlist::getUserWishList(user[, type='user'])
To get all wishlist items from a user, specify the user_id.
type ['user', 'session'] is an optional parameter wich tells the service if the user is an application authenticated user_id or
a custom session/cookie id.
Wishlist::removeUserWishList(user[, type='user'])
To remove all wishlist items from a user, specify the user_id.
type ['user', 'session'] is an optional parameter wich tells the service if the user is an application authenticated user_id or
a custom session/cookie id.
Wishlist::removeByItem(item, user[, type='user'])
To remove a particular item, specify the item and user respectively.
type ['user', 'session'] is an optional parameter wich tells the service if the user is an application authenticated user_id or
a custom session/cookie id.
Wishlist::count(user[, type='user'])
Total wishlist items from a user.
Wishlist::getWishListItem(item, user[, type='user'])
To get particular wishlist item, specify the item and user respectively.
type ['user', 'session'] is an optional parameter wich tells the service if the user is an application authenticated user_id or
a custom session/cookie id.
Wishlist::assocSessionWishListToUser(user_id, session_id)
To associate a particular session_id wishlist to an authenticated user.
A user who has number of favorites while unlogged, if he logins, this method could be run to preserve the potentialy new wishlist items.
You can the load item detail using laravel Eloquent association:
or you can access it directly invoking the appropriate Eloquent model