Table of Contents
- 1) Run below command to install this package
- 2) Put 'add to cart ' form inside view files of product listing after 'Cost' i.e
- 3) Also create cart.blade.php views file under resources/views/products and put below code
- 4) Now create cart.blade.php inside resources/views/includes and put below
- 5) Put below on routes/web.php file
- 6) Create a Controller ShopController.php then functions add_to_cart ,cart .
- Setup Checkout Page
- 1) Put below button in cart.blade.php found under resources\views\products
- 2) Put below in route file routes/web.php
- 3) Create a 'checkout' function in ShopController.php as shown below
- 4) Create view file checkout.blade.php inside resources/views/products/
- PayPal payment gateway integration in Laravel
- Create Database table to hanlde orders.
- Now create modal file for this table inside 'App' folder
- Order.php
- OrderItem.php
- OrderStatus.php
- OrderStatusChange.php
- Install laravel paypal package
- Now put below inside your route file routes/web.php
- Create PaypalController.php
- Now put below 3 functions inside your ShopController.php
- Now create a view file 'order_placed.blade.php' inside 'resources/views/products' folder
- Your Payment Status Failed for your Order# {{$orderId}} of Rs. {{$orderAmount}}
- THANK YOU FOR YOUR PURCHASE !
- Checkout
- Summary
1) Run below command to install this package
Open config/app.php and add this line to your Service Providers Array
then add this line to your Aliases in same file
2) Put 'add to cart ' form inside view files of product listing after 'Cost' i.e
resources/views/includes/product_loop.blade.php (for home page latest product) resources/views/products/product_details.blade.php
3) Also create cart.blade.php views file under resources/views/products and put below code
@endsection
4) Now create cart.blade.php inside resources/views/includes and put below
Note : you should have jquery file inside section in layout/master.blade.php
ex:
5) Put below on routes/web.php file
6) Create a Controller ShopController.php then functions add_to_cart ,cart .
Now open the website and click on the 'add to cart' button to test .
If you are looking to hire PHP Laravel Developer, freelancer in Delhi, Noida, India. Visit here . Setup Checkout Page
On this tutorial series of Laravel ecommerce from scratch, we have already setup of basic ecommerce using cart package . Now here we will create checkout page .
1) Put below button in cart.blade.php found under resources\views\products
2) Put below in route file routes/web.php
3) Create a 'checkout' function in ShopController.php as shown below
also call below use Auth;
4) Create view file checkout.blade.php inside resources/views/products/
and put below code
PayPal payment gateway integration in Laravel
A payment gateway is a merchant service provided by an e-commerce application service provider that authorizes credit card or direct payments processing for e-businesses, online retailers etc.
Some payment gateway are
- ccavenue
- payu
- ebs
- Bank's payment gateway ( HDFC, ICICI )
To integrate paypal payment gateay in laravel follow below steps
Create Database table to hanlde orders.
We will create below 4 tables
Now create modal file for this table inside 'App' folder
Here model files
Order.php
OrderItem.php
OrderStatus.php
OrderStatusChange.php
Install laravel paypal package
We wil be using this package https://packagist.org/packages/srmklive/paypal Execute below command
# Add the service provider to your providers array in config/app.php file like:
# Add the alias to your aliases array in config/app.php file like:
# Run the following command to publish configuration:
after this command , it generates config/paypal.php
Note: you need to get Paypal API credential to use here - Login to your paypal account
- From top menu click on Tool-> Business Setup
- Then click 'Payment Setup'
- Click on the 1st option then 'continue'
- I have mentioned in the screenshot of this tutorials, follow this
Now put below inside your route file routes/web.php
Create PaypalController.php
Above controller contains payment process function and 2 other function to handle success and cancel payment
Now put below 3 functions inside your ShopController.php
Now create a view file 'order_placed.blade.php' inside 'resources/views/products' folder
it will display message after returning from payment gateway.
Put below inside this file
Now finally overwrite your checkout.blade.php file as shown below
Now test this functionality by clicking 'Place Order' button in checkout page
Note :
PayPal provide developer testing account for testing purpose .
You can use this login details to test how payment processes in paypal website .
Steps to create paypal developer testing account
To create a PayPal Developer Testing Account, follow these steps:
Step 1: Sign Up for PayPal Developer Account
- 1. Go to (https://developer.paypal.com/).
- 2. Click Log in to Dashboard (If you don’t have an account, click Sign Up and create one).
- 3. Use your PayPal business account to log in or create a new one.
- 1. Once logged in, go to the Sandbox section in the left menu.
- 2. Click Accounts under Sandbox.
- 3. Click Create Account and choose the type of account: Business (Merchant Account) → For testing as a seller. Personal (Buyer Account) → For testing as a customer.
- 4. Fill in the required details and click Create.
- Navigate to My Apps & Credentials from the left menu.
- In the Sandbox section, click Create App.
- Enter an app name and link it to your Sandbox Business Account.
- Click Create App, and you will see:
- Client ID
- Secret Key
- Use the sandbox buyer account to simulate purchases.
- Use the sandbox seller account to receive payments.
- View test transactions under Sandbox > Accounts > View Transactions.
can change paypal test and live mode inside config/paypal.php
Summary
In this tutorial, we covered the essential steps to create an E-commerce website project using PHP Laravel Framework . We started by setting up the Laravel environment and database, then moved on to authentication, product management, shopping cart functionality, and payment gateway integration. Additionally, we implemented an order management system and optimized the website for performance and security.
By following this guide, you have gained the foundational knowledge to build a fully functional e-commerce website with Laravel. You can further enhance the project by adding features such as advanced filtering, an admin dashboard, customer reviews, and order tracking.
Laravel provides a powerful and flexible framework for developing scalable e-commerce applications. Keep learning, experimenting, and refining your project to create a high-quality online store. We also provide laravel training ecommerce project based.