Using Laravel for E-Commerce: Tutorial & Live Demo
Tags: laravel, webdev, tutorial, php
Published: 2021-02-04 18:37:13

---
title: Using Laravel for E-Commerce: Tutorial & Live Demo
published: true
tags: laravel, webdev, tutorial, php
canonical_url: https://snipcart.com/blog/laravel-ecommerce-website-tutorial
---

PHP is, in *some* ways, the backbone of the Internet. I mean, it is at the core of [WordPress](https://snipcart.com/blog/wordpress-static-site-generator), which powers [39.9%](https://w3techs.com/technologies/details/cm-wordpress) of all the websites today. It is also used by the biggest social media; Facebook.

But I have to admit, I’ve never had the chance to explore it fully.

Today is the day I jump into PHP. However, I’ll begin my journey with the darling framework that is Laravel (I’ve heard it makes it easy to build secure, scalable full-stack projects from the start!).

![Jumping in PHP](https://snipcart.com/media/205654/jumpinphp.gif)

More especially, I’ll try to build a Laravel-powered [e-commerce web app](https://snipcart.com/blog/react-ecommerce-tutorial).

Hopefully, this will show you the benefits Laravel can bring to your next e-commerce venture.

Here’s what the tutorial will cover:

- Project Setup with Sail
- Basic product listing generation, migration, and seeding
- Using advanced models for product options
- Front-end wiring
- Integrating Snipcart

Time to put my PHP skills to test!

## Laravel & e-commerce: quick context

Laravel is an open-source PHP web framework used to build sites & web apps.

It has a smooth learning curve, removes some quirks of building with PHP, and has many modern built-in libraries. Some say it's the Ruby on Rails PHP equivalent.

With Laravel, you can leverage [Composer](https://getcomposer.org/doc/00-intro.md) to manage dependencies & packages. Many useful packages allow you to fast-track your Laravel development. Think stuff like debugging, authentication, API interactions, etc. Sites like Packagist & Packalyst are great resources to find helpful Laravel packages.

Since September 2020, [Laravel 8 is publicly available](https://auth0.com/blog/whats-new-in-laravel-8/). It introduces features such as Laravel Jetstream, model factory classes, migration squashing, job batching, improved rate-limiting, dynamic Blade components, Tailwind pagination views, time testing helpers, and more.

**Tools for e-commerce on Laravel?**

Of course, there are existing e-commerce packages for Laravel. They can help to set up e-commerce functionalities on your Laravel app quickly.

Here’s a curated list of the most popular ones:

- [Bagisto](https://bagisto.com/en/) — Code-driven & multi-featured Laravel package for e-commerce. Free & open-source.
- [Aimeos](https://aimeos.org/integrations/laravel-ecommerce-package/) — A Laravel e-commerce package and online shop solution. Free & open-source.
- [AvoRed](https://www.avored.com/) — A modular and customizable PHP shopping cart. Free & open-source.
- [Vanilo](https://vanilo.io/) — This one’s actually an e-commerce framework (like Magento or Prestashop) for Laravel.
- [GetCandy](https://getcandy.io/) — An headless Laravel e-commerce API. Free & open-source.

So, where does that lead us?

The three e-commerce options with Laravel are pretty much:

1. Pick a Laravel-powered CMS and add custom e-commerce to it.
2. Use e-commerce packages built to extend your app.
3. Build your own e-commerce application from the ground up.

**First one?** Fast & easy. That’s what we did for the first version of this post, using PyroCMS and then integrating Snipcart as the custom shopping cart.

**Second one?** Interesting. We might do it in another post at some point!

**Third one?** Close to what we're doing here. But building the whole application from the ground up, including e-commerce capabilities, would be highly time-consuming.

Instead, I’ll show you how you can build a store from scratch using pure Laravel and then adding Snipcart to enable e-commerce and shopping cart customization.

All these options have in common the benefits you’ll win overusing a full-on e-commerce CMS—high scalability, easy customization, detached e-commerce functionalities, etc.

I'm thrilled to be operating inside a Laravel project for this demo. Unlike many of our [Jamstack](http://snipcart.com/blog/jamstack)/static site tuts, it'll be super easy to handle any backend logic for our store.

## Tutorial: building an e-commerce website with Laravel

![Laravel E-Commerce Website With Snipcart](https://snipcart.com/media/205655/laravelsnipcart.png)

**Prerequisites**

I assume you already have a working installation of PHP and [Composer](https://getcomposer.org/) running. If not, you can install them [here](https://www.php.net/) and [here](https://getcomposer.org/).

For this tutorial, we will use [Sail](https://laravel.com/docs/8.x/sail). 

Introduced with Laravel 8, it is a light-weight command-line interface for interacting with Laravel’s default Docker development environment that will streamline our development environment and database setup. Sail will allow us to quickly setup a development environment and database completely isolated from our local environment.

Since Sail interacts with a Docker environment, that means you will also need [Docker Desktop](https://www.docker.com/products/docker-desktop) (a great tool for app development these days). If you prefer, of course, you could plug in a local SQL database or use [Homestead](https://laravel.com/docs/8.x/homestead) from Laravel. The latter is an all-in-one vagrant image that allows you to get started quickly.

→ Read the full post [here](https://snipcart.com/blog/laravel-ecommerce-website-tutorial)