Laravel Shopping Cart with React Js

Okay friends here i am starting new tutorial series of Laravel Shopping cart with ReactJs for beginners. 

First of all,  I just install Laravel with composer command

composer create-project --prefer-dist laravel/laravel ProjectName

now create a database with products table(data), and open you .env from Laravel project and set some code as below

DB_HOST=127.0.0.1
DB_PORT=8889(for mac)
DB_DATABASE=DataBaseName
DB_USERNAME=root
DB_PASSWORD=root(keep empty if you are on window)

Now we need to play with products data, i will prefer do via model so just create simple new model same name of your products table with command:

php artisan make:model products

Open your route file(Web.php) from Laravel project. inside that file we need to create new route to return products data as json Array. 

Route::get('products', function(){ return App\products::all(); });



Here is library which i use for shopping cart

https://github.com/darryldecode/laravelshoppingcart

Command you need to run for install this package:

composer require "darryldecode/cart:~4.0"

Now create Simple route functions (in web.php) to manage your shopping cart:


Add to cart:


Route::get('add', function(){
$add = Cart::add([
'id'=>1,
'name'=>'sdbh dnd ',
'price' =>350,
'quantity' => 2,
'attributes' => [
'color' => 'red',
'size' => 'xl'
]
]);
if($add){
return Cart::getContent();
}
});

Cart Data:

Route::get('cart', function(){
return Cart::getContent();
});
Clear Cart:

Route::get('clear', function(){
$clear = Cart::clear();

if($clear){
return Cart::getContent();
}
});

Demo:



Video Tutorial