Step 5 – Building the Frontend Store Page in Laravel

🛍️ Step 5 – Building the Frontend Store Page in Laravel

Making your products displaying to customers / producing your product to market.

In the earlier steps of this series, you created a Laravel e-commerce project, designed its database schema, and built a full CRUD system for managing products. That gives you the power to add, edit, and delete products in the backend.

But so far, all that work lives behind the scenes. A real e-commerce website must allow customers to browse products, view details, and eventually add them to their cart. That’s where the frontend store page comes in.

This step will walk you through creating the public shop interface of your Laravel application. We’ll cover everything from the controller logic to the Blade templates, and sprinkle in practical advice and UX tips from real-world experience.


🎯 Goals for This Step to build e-commerce

Let’s clearly define what we are building so you understand the roadmap:

  • A main shop page that lists all products in a grid layout as the above.
  • Each product shows image, name, price, and a link to view more with modal popup with gallery imgagesd.
  • A product detail page that shows full description, stock, and an “Add to Cart” button.
  • Use of Bootstrap to quickly make it look clean and responsive.
  • Prepare the structure for future steps (cart and checkout).

In short, you’re turning your data into a real storefront.


🧠 Why This Matters

This is often the first impression users get of your website. A sloppy, text-heavy page will turn people away. But a clean, image-driven design builds trust and engagement.

Also, by building this yourself instead of using a ready-made template, you’ll learn how to:

  • Connect Laravel models to frontend pages
  • Use Blade templating effectively
  • Structure your routes for public pages
  • Paginate products for better performance

This is foundational Laravel knowledge that applies to almost any type of app.


⚙️ Step 1: Create the ShopController

In Laravel, the controller will handle the logic of fetching products from the database and passing them to the views.

Run the Artisan command to create it:

php artisan make:controller ShopController

This creates app/Http/Controllers/ShopController.php.

Open it and add:

namespace App\Http\Controllers;

use App\Models\Product;

class ShopController extends Controller
{
    // Show all products
    public function index()
    {
        $products = Product::latest()->paginate(12);
        return view('shop.index', compact('products'));
    }

    // Show a single product
    public function show($id)
    {
        $product = Product::findOrFail($id);
        return view('shop.show', compact('product'));
    }
}

What’s happening here:

  • We fetch products with Product::latest() so newest ones appear first.
  • paginate(12) automatically limits to 12 per page and adds pagination links.
  • The show method finds a specific product using its ID and displays details.

By separating these two actions (index and show), your code stays clean and maintainable.


⚙️ Step 2 Define Public Routes

Your controller won’t work until you wire it into routes.

Open routes/web.php and add:

use App\Http\Controllers\ShopController;

Route::get('/', [ShopController::class, 'index'])->name('shop.index');
Route::get('/product/{id}', [ShopController::class, 'show'])->name('shop.show');

We use resource concept on the blade templates that contains multiple functions on single routes.

Key notes:

  • The root / URL now loads your shop’s homepage.
  • /product/{id} shows details for any product by ID.
  • Using named routes (name('shop.index')) helps if you ever change URLs later.

Make sure these routes are placed below your admin routes so they don’t conflict.


⚙️ Step 3 : Build the Blade Views

Now for the fun part: designing the HTML your customers will see.

We will create two views:

  • resources/views/shop/index.blade.php
  • resources/views/shop/show.blade.php

These pages will use Bootstrap classes for fast styling.


🖼 index.blade.php — Product Grid

Important points:

  • The row and col-md-3 classes create a 4-column responsive grid.
  • We use object-fit: cover; to keep all product images uniform.
  • $products->links() shows Laravel’s built-in pagination UI.
  • Using shadow-sm and card h-100 gives subtle visual polish.

📄 show.blade.php — Product Detail Page

@extends('layouts.app')

@section('content')
<div class="container">
  <div class="row">
    <div class="col-md-5">
      @if($product->image)
        <img src="{{ asset('storage/'.$product->image) }}" 
             class="img-fluid rounded shadow" 
             alt="{{ $product->name }}">
      @endif
    </div>
    <div class="col-md-7">
      <h2>{{ $product->name }}</h2>
      <h4 class="text-success">${{ $product->price }}</h4>
      <p class="mt-3">{{ $product->description }}</p>
      <p><strong>Stock:</strong> {{ $product->stock }}</p>
      <button class="btn btn-success btn-lg mt-3">Add to Cart</button>
    </div>
  </div>
</div>
@endsection

What makes this page good:

  • Clear product name and price at the top.
  • Big image with img-fluid for responsiveness.
  • A dedicated “Add to Cart” button we’ll wire up in the next step.
  • Shows stock quantity to build urgency and trust.

⚙️ Step 4 — Using a Layout Template

To avoid repeating HTML (like <head> and navbars), place both shop views inside your existing layouts.app layout.

If you don’t have it yet, create resources/views/layouts/app.blade.php:

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>{{ config('app.name','MyShop') }}</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
  <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
    <div class="container">
      <a class="navbar-brand" href="{{ route('shop.index') }}">MyShop</a>
    </div>
  </nav>

  <main class="py-4">
    @yield('content')
  </main>

  <footer class="text-center py-4 text-muted">
    &copy; {{ date('Y') }} MyShop. All rights reserved.
  </footer>
</body>
</html>

This gives your shop a consistent look.


⚙️ Step 5 — Adding Some Demo Products (Optional)

If your database is still empty, create a few demo products so you can see the frontend working.

Use tinker:

php artisan tinker

Then:

Product::create([
  'name'=>'Coffee Mug',
  'description'=>'A stylish ceramic mug for coffee lovers.',
  'price'=>9.99,
  'stock'=>20,
  'category_id'=>1
]);

Repeat this for 3–4 products, or seed them using Laravel factories later.


🧩 UX and Design Tips

Building the frontend isn’t just about code — it’s about creating a smooth experience. Here are battle-tested tips:

  • Keep product cards consistent — same image height, same text alignment.
  • Show price clearly and use a distinct color like green.
  • Add hover effects on cards using CSS (.card:hover { transform: scale(1.02); }) to make it interactive.
  • Use categories as filters — in the future, add a sidebar to filter by category.
  • Make it mobile-friendly — test on your phone often.

These touches can make your site feel professional even at an early stage.


✅ Summary

At this stage of your Laravel e-commerce journey, you now have:

  • A public-facing shop homepage that shows your products
  • Clean, responsive product cards
  • A product detail page with description, price, and stock
  • A strong foundation for the upcoming cart and checkout features

This is a major milestone — you’ve turned your backend data into something customers can actually see.


🚀 What’s Next

In Step 6, we will build a shopping cart system that allows users to:

  • Add products to their cart
  • View their cart contents
  • Update quantities and remove items

That’s where your store starts feeling real to customers.

Leave a Comment