1. Go to this page and download the library: Download binafy/laravel-cart 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/ */
binafy / laravel-cart example snippets
'users' => [
...
/*
* Specify the type of foreign key being used (e.g., 'id', 'uuid', 'ulid').
* For non-standard IDs, make sure to add the relevant traits to your models.
*/
'foreign_key_type' => 'id', // Options: uuid, ulid, id
],
use Binafy\LaravelCart\LaravelCart;
LaravelCart::driver('session')->storeItem($item, $userId|null);
LaravelCart::storeItem($item $userId|null);
use Binafy\LaravelCart\LaravelCart;
LaravelCart::driver('database')->storeItem($item, $userId|null);
LaravelCart::driver('session')->removeItem($item);
use \Binafy\LaravelCart\Models\Cart;
$cart = Cart::query()->firstOrCreate(['user_id' => $user->id]);
$cartItem = new CartItem([
'itemable_id' => $itemable->id,
'itemable_type' => $itemable::class,
'quantity' => 1,
]);
$cartItem->itemable()->first(); // Return Model Instance
use Binafy\LaravelCart\Cartable;
class Product extends Model implements Cartable
{
public function getPrice(): int
{
//
}
}