PHP code example of mohammadv184 / laravel-cart

1. Go to this page and download the library: Download mohammadv184/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/ */

    

mohammadv184 / laravel-cart example snippets


$product=Product::find(1);
Cart::put([
    "price"=>10,
    "quantity"=>1
],$product);

$product=Product::find(1);
Cart::update(2,$product); // Will update the quantity

$id = 'Biuwla5871';
Cart::update($id, 2); // Will update the quantity

Cart::update(['price' => 1000],"16cdac2cs8"); // Will update the price
$product=Product::find(1);
Cart::update(['id'=>"1c6a4c6a75",'price'=>1000], $product); // Will update the id and price

$product=Product::find(1);
Cart::delete($product);

$id = 'da39a3ee5e';
Cart::delete($id);

$product = Product::find(1);
Cart::get($product);

$id = 'da39a3ee5e';
Cart::get($id);

Cart::all();

Cart::flush();

Cart::totalPrice();

// Add some items in your Controller.
$product=Product::find(1);
Cart::put(['quantity'=>1,'price'=>9.99],$product);
$product=Product::find(2);
Cart::put(['quantity'=>2,'price'=>10],$product);
// Display the content in a View.
<table>
   	<thead>
       	<tr>
           	<th>Product</th>
           	<th>quantity</th>
           	<th>Price</th>
        </tr>
   	</thead>
   	<tbody>
   		@foreach(Cart::all() as $row)
       		<tr>
           		<td>
               		<p><strong>{{$row->product->name}}</strong></p>
               	</td>
           		<td><p>{{$row->quantity}}</p></td>
           		<td>${{$row->price}}</td>
       		</tr>
	   	@endforeach
   	</tbody>
   	
   	<tfoot>
   		<tr>
   			<td colspan="2">&nbsp;</td>
   			<td>Total</td>
   			<td>{{Cart::totalPrice()}}</td>
   		</tr>
   	</tfoot>
</table>