PHP code example of javcorreia / laravel-wishlist

1. Go to this page and download the library: Download javcorreia/laravel-wishlist library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

javcorreia / laravel-wishlist example snippets


return [
    'item_model' => App\Models\Product::class,
];



use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        $schemaTableName = config('wishlist.table_name');

        Schema::table($schemaTableName, function (Blueprint $table) {
            $table->softDeletes();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        $schemaTableName = config('wishlist.table_name');

        Schema::table($schemaTableName, function (Blueprint $table) {
            $table->dropSoftDeletes();
        });
    }
}; 

namespace App;

use Illuminate\Database\Eloquent\SoftDeletes;
use javcorreia\Wishlist\Models\Wishlist as BaseWishlist;

class MyWishlist extends BaseWishlist
{
    use SoftDeletes;
}



return [

    // (...)
    
    /*
    |--------------------------------------------------------------------------
    | Custom Wishlist model
    |--------------------------------------------------------------------------
    |
    | This option allows for the extension of the wishlist Model
	| App\Models\MyWishlist::class
    |
    */
    'model' => App\Models\MyWishlist::class

];

namespace App\Http\Controllers;

use javcorreia\Wishlist\Facades\Wishlist;

// ...

// add item to user_id
Wishlist::add(15, 1);

// add item to session_id
Wishlist::add(15, 'CUSTOM_SESSION_ID', 'session');

// remove item from user_id
Wishlist::remove(2, 1);

// remove item from session_id
Wishlist::remove(2, 'CUSTOM_SESSION_ID', 'session');

// get all items from user_id
Wishlist::getUserWishList(1);

// get all items from session_id
Wishlist::getUserWishList('CUSTOM_SESSION_ID', 'session');

// remove all items from user_id
Wishlist::removeUserWishList(1);

// remove all items from session_id
Wishlist::removeUserWishList('CUSTOM_SESSION_ID');

// remove item from user_id
Wishlist::removeByItem(15, 1);

// remove item from session_id
Wishlist::removeByItem(15, 'CUSTOM_SESSION_ID', 'session');

// total items from user_id
Wishlist::count(1);

// total items from session_id
Wishlist::count('CUSTOM_SESSION_ID', 'session');

// get item from user_id
Wishlist::getWishListItem(15, 1);

// get item from session_id
Wishlist::getWishListItem(15, 'CUSTOM_SESSION_ID', 'session');

// get item from user_id
Wishlist::assocSessionWishListToUser(1, 'CUSTOM_SESSION_ID');

$result = Wishlist::getUserWishList(1)->load('item');

$result = Wishlist::getUserWishList(1);
$product = Product::find($result->id);
shell
$ php artisan vendor:publish --provider="javcorreia\Wishlist\Providers\WishlistServiceProvider"
shell
$ php artisan migrate
shell
$ php artisan config:cache
shell
$ php artisan make:migration add_softdelete_to_wishlist
shell
$ php artisan migrate
shell
$ php artisan make:model MyWishlist