
How to set up an eCommerce website in Laravel PHP Framework
Laravel is a great flexible and most popular PHP framework for building web applications. It has already taken the PHP framework scene by storm. So, its only logical that clients come up to discuss their eCommerce website development needs with us using Laravel. Now, we already provide WooCommerce development services and heavy-hitting Magento eCommerce. However, there are clients who are more interested in a eCommerce solution for small business rather an open-source one. For them, this is a handy guide to set up your ecommerce website in Laravel. Here, we provide guidelines on how to build an eCommerce (A site where you can sell you products) website using Laravel. The first step is to set up Laravel on the local environment. Like other modern framework, Laravel uses composer for installation and manage dependencies. To install Laravel via composer use this command in the shell.composer create-project --prefer-dist laravel/laravel ecommerce-website
Designing Laravel eCommerce Frontend
Designing an eCommerce website in Laravel is very simple. You can choose any HTMl5/CSS theme of your liking. To integrate it with the Laravel framework, all you must do is to copy the theme resources (css, js and images) into the Laravel resources directory and then specify them in the webpack.mix.js file. Laravel Mix is used for minifying resource files, but to use this feature, you must first pull it via npm command npm install. You can use Laravel Mix like given in the documentation.mix.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css');
For more detail please check the documentation. You can also use AngularJS for frontend.
Related: Responsive website design with Bootstrap, jQuery and AngularJS
In a standard e-commerce application, we have a mixture of following modules. Some businesses will have requirement for more and some less. However, we will touch all of these to give a flavor of Laravel eCommerce.
- Product Page Design
- Shopping Cart Design
- Shipping Method Integration
- Payment Method Integration
- Generating Invoices
- Product Delivery
1. Product Page Design
All companies are different with product types like physical products, bundle products, simple products and digital. Here we will only discuss products from front-end perspective. Laravel has a very cool templating system called blade. Which supports view partial, master layout etc. and keeps the presentation code clean and manageable. Laravel has also very flexible pagination feature, So, displaying paginated products on frontend is a breeze.2. Shopping Cart Design
Shopping cart is basically a virtual basket which holds the customer products. Shopping cart package helps in presenting this information to the customer. Some of the shopping cart packages developed for Laravel are darryldecode/cart, overtrue/laravel-shopping-cart, syscover/shopping-cart etc. You can integrate any of these with the Laravel in the same fashion as shown below.composer require darryldecode/cart
Configuration:
- In the config/app.php file add this line to your Service Providers array
Darryldecode\Cart\CartServiceProvider::class
- In the config/app.php add this line to your Aliases
'Cart' => Darryldecode\Cart\Facades\CartFacade::class
After that, the package is ready to use and can be referenced like that
Cart::add(array(
'id' => 456,
'name' => 'Sample Item',
'price' => 67.99,
'quantity' => 4,
'attributes' => array()
));
3. Shipping Method Design
Shipping is an important part of the business if it’s dealing in the physical products. With the shipping methods, we specify the shipping service and cost for it. Laravel provides USPS package, which also validates the shipping address besides providing shipping services and shipping cost calculation. Please check the documentation for detail. To integrate this in Laravel, follow these instructionscomposer require johnpaulmedina/laravel-uspsIntegration with Laravel:
- In the config/app.php file add this line to your Service Providers array
'Usps\UspsServiceProvider',
- In the config/app.php add this line to your Aliases
'Usps' => 'Usps\Facades\Usps'
There are other packages available for shipping at packagist.org.
4. Payment Method Integration
Other step involved in Laravel ecommerce application is to charge the customer for the purchased product, using payment gateways i.e. Paypal, Klarna, Adyen, Stripe, Payfast, Mollie etc. Laravel provides an official package for payment named Laravel Cashier for accepting payment from Paypal Braintree and Stripe gateways. You can install it via Composercomposer require "laravel/cashier":"~7.0"
Next, register it by putting Laravel\Cashier\CashierServiceProvider in the config/app.php service providers array. We provide support and installation services for all the above-mentioned payment gateways.
5. Generate Invoices
After successful payment, sending order invoice to the customer is a standard procedure in Laravel eCommerce applications. Luckily, this feature is already available in the Cashier package. This package provides an invoice in PDF format so to get the benefit of this feature you must install dompdf package. Use the following composer command to install dompdfcomposer require dompdf/dompdf
For more detail on how to generate an invoice via cashier package please check its documentation.
6. Product Delivery Design
The last step involved in the e-commerce application is to deliver physical product to the customer. Automation of this process is optional, but here are the steps to automate the delivery process. There are a lot of shipping fulfillment companies like Verde, USPS etc. USPS not only provide the tracking service but also provide address validation, shipping rate calculation based on product weight and shipping address etc. You can check the installation instructions in the shipping section above. USPS provides the tracking of the package and keep the company and customer updated via tracking ID for that package. The above steps will complete the design of front-end for an Laravel ecommerce website. Next, we’ll discuss what you require to setup the admin panel for your Laravel ecommerce webshop.Designing Laravel eCommerce Backend
Let’s talk about the admin panel for the website. Following are the major components for admin panel.- Authentication
- Users Roles
- Categories
- Product Management
- Order Fulfillment
- Reporting
- Site Pages
1. Authentication
User authentication means that allow only those who have legal access to the system. Authentication is something Laravel provides out of the box. Just run the following command and it will generate the authentication system for your application.php artisan make:auth
Related: How to import WordPress users into Laravel?
2. Users Roles(Authorization)
Authorization is to check that the user has the privilege to perform a specific action. Laravel has built in feature called middleware which provides filtering service. If your system has very basic level authorization then custom middleware will be ok but If you have more complex scenario than the use of third party package will be beneficial. Laravel has many packages which provide users roles(authorization) functionality. Here we will show you how to use Ultraware/roles composer require ultraware/roles
Integration with Laravel:
- In the config/app.php file add this line to your Service Providers array
Ultraware\Roles\RolesServiceProvider::class,
- Also, add the following middlewares in the app/Http/Kernal.php file
'role' => \Ultraware\Roles\Middleware\VerifyRole::class,
'permission' => \Ultraware\Roles\Middleware\VerifyPermission::class,
'level' => \Ultraware\Roles\Middleware\VerifyLevel::class,
You can manage roles, level of roles and their permissions with Utraware package.
3. Categories
This for categorization of the products. This is a general CRUD operation. You can use Laravel Artisan to set up the model and controller along with writing a migration.4. Product Management
Product management basically means adding, updating, archiving and deleting products. There is two main type of products i.e. physical and digital products that can be further divided into:- Simple Products: A normal product with simple attributes.
- Variable Products: Which offers variations i.e. size, color etc.
5. Order Fulfillment
Order fulfillment refers to the steps from order receiving to the delivery of the product(s) to a customer. If you are using your own fulfillment process then it should look like this.- Order is received and the customer is notified about it.
- Order is sent to the warehouse using invoice
- Order is picked
- Order is packed for shipping
- Order is shipped and customer is notified
- Order arrives at the customer location.
6. Reports
Reporting is the most important section of the eCommerce website. It gives you the better picture for your sales, stocks etc. You can use two types of reporting tabular and graphical. For graphical reporting, you can use the frontend library named highcharts, which is one the best library in the market and gives you full control over how you want to show the graphical reporting.7. Site Pages
The other thing need to manage from admin panel is the site pages, like about, contact us information, privacy policy etc. Which are just a normal Laravel CRUD tasks. After making a Laravel eCommerce website, next step would be the hosting of the site.Hosting a Laravel eCommerce Website
Any company spending big on setting up a custom Laravel eCommerce shop shouldn’t thrift on reliable hosting services. For Laravel, we suggest UKFast.com, an award winning hosting company from UK. They provide dedicated clouds and a support team out of this world. You can also host with Amazon EC2 cloud easily. Some extra steps to make your ecommerce website, more reliable, fast and user-friendly. Loading speed is considered as a main factor in providing good user experience, Laravel has many built-in features i.e. caching, minification etc. always enable caching for production server only, please check the documentation for all the available caching configuration options in laravel. Other thing we discussed is the minification, Laravel provides Laravel Mix for it. Though which the assets could be minified and also combined as a single file which in term reduced file size and HTTP requests as there are 4 HTTP requests involved per single file.SEO in Laravel eCommerce Website
SEO is important to rank your site by the search engines, Caffeinated SEO helps in generating SEO meta data for the laravel application. Integrating this package in laravel is same as other packages.Email Campaigns
Running email campaigns for products promotion, user verification and website news etc. Being a MailChimp certified company, we recommend the most popular option of running email campaigns, MailChimp. skovmand/mailchimp-laravel, spatie/laravel-newsletter are some packages that provide MailChimp integration with Laravel. You can also provide a rating system for your products, ghanem/rating is a Laravel package that provides the entire rating system for your Laravel application.Laravel eCommerce Mobile App
If your eCommerce website is built in Laravel then its fairly straight-forward to generate a mobile app. Laravel comes with built-in APIs that can expose data for the mobile app. Mobile app for eCommerce can have many benefits for business. And with Laravel, its a no-brainer to start an eCommerce app as well.Ready eCommerce Packages
Some ready Laravel ecommerce packages are available which have varying degrees of implementation and success. You can choose one of the following to get a head start.- https://aimeos.org/integrations/laravel-ecommerce-package/
- https://packagist.org/packages/mage2/laravel-ecommerce
- https://github.com/ablunier/laravel-ecommerce