Skip to main content

Overview

Macuin’s routes are defined in routes/web.php. All routes return Blade views and use named routes for easy reference throughout the application. Currently, the application uses closure-based routes for simplicity.

Route Configuration

Routes are defined using Laravel’s Route facade:
routes/web.php
<?php

use Illuminate\Support\Facades\Route;

Route::get('/', function () {
    return view('home.index');
})->name('index');

Route::get('/catalogo', function () {
    return view('catalogos.catalogo');
})->name('catalogo');

Route::get('/registro', function () {
    return view('auth.registro');
})->name('registro');

Route::get('/login', function () {
    return view('auth.login');
})->name('login');

Route::get('/carrito', function () {
    return view('carrito.carrito');
})->name('carrito');

Route::get('/pedidos', function () {
    return view('pedidos.pedido');
})->name('pedidos');

Route::get('/pedido-detalle/{id}', function ($id) {
    return view('pedidos.pedido-detalle', ['id' => $id]);
})->name('pedido-detalle');

Route List

Homepage

GET /

Route Name: index
View: home.index
Description: Main landing page of the application
Route::get('/', function () {
    return view('home.index');
})->name('index');

Catalog

GET /catalogo

Route Name: catalogo
View: catalogos.catalogo
Description: Product catalog page displaying automotive parts
Route::get('/catalogo', function () {
    return view('catalogos.catalogo');
})->name('catalogo');

Authentication

GET /registro

Route Name: registro
View: auth.registro
Description: User registration page

GET /login

Route Name: login
View: auth.login
Description: User login page
Route::get('/registro', function () {
    return view('auth.registro');
})->name('registro');

Shopping Cart

GET /carrito

Route Name: carrito
View: carrito.carrito
Description: Shopping cart page for reviewing items before checkout
Route::get('/carrito', function () {
    return view('carrito.carrito');
})->name('carrito');

Orders

GET /pedidos

Route Name: pedidos
View: pedidos.pedido
Description: Order list page

GET /pedido-detalle/{id}

Route Name: pedido-detalle
View: pedidos.pedido-detalle
Description: Order details page
Route::get('/pedidos', function () {
    return view('pedidos.pedido');
})->name('pedidos');
The order details route accepts an {id} parameter that is passed to the view for displaying specific order information.

Named Routes

All routes use the ->name() method to assign a name. Named routes allow you to generate URLs or redirects without hardcoding the path:

Generating URLs

// Generate URL to named route
$url = route('catalogo');
// Returns: http://localhost:8000/catalogo

// Generate URL with parameters
$url = route('pedido-detalle', ['id' => 123]);
// Returns: http://localhost:8000/pedido-detalle/123

In Blade Templates

{{-- Link to catalog --}}
<a href="{{ route('catalogo') }}">Ver Catálogo</a>

{{-- Link to order details --}}
<a href="{{ route('pedido-detalle', ['id' => $orderId]) }}">Ver Pedido</a>

{{-- Check current route --}}
@if (Route::currentRouteName() === 'index')
    <p>You are on the homepage</p>
@endif

In Controllers

// Redirect to named route
return redirect()->route('login');

// Redirect with parameters
return redirect()->route('pedido-detalle', ['id' => $order->id]);

Route Parameters

The application currently uses one route parameter:

Order ID Parameter

Route::get('/pedido-detalle/{id}', function ($id) {
    return view('pedidos.pedido-detalle', ['id' => $id]);
})->name('pedido-detalle');
  • Parameter: {id} - The order identifier
  • Type: String (no constraint defined)
  • Usage: Passed to the view for displaying order details
Route parameters are automatically dependency-injected into the route closure or controller method.

URL Structure

Macuin uses clean, SEO-friendly URLs:
URLPurposeSpanish Translation
/HomepageInicio
/catalogoProduct catalogCatálogo
/registroRegistrationRegistro
/loginLoginIniciar sesión
/carritoShopping cartCarrito
/pedidosOrders listPedidos
/pedido-detalle/{id}Order detailsDetalle del pedido
URL paths use Spanish terms to match the application’s primary language.

Route Groups and Middleware

Currently, the application does not use route groups or middleware. As the application grows, you can organize routes using:

Middleware Groups

// Example: Protected routes requiring authentication
Route::middleware(['auth'])->group(function () {
    Route::get('/pedidos', function () {
        return view('pedidos.pedido');
    })->name('pedidos');
    
    Route::get('/carrito', function () {
        return view('carrito.carrito');
    })->name('carrito');
});

Route Prefixes

// Example: Admin routes with prefix
Route::prefix('admin')->group(function () {
    Route::get('/dashboard', [AdminController::class, 'dashboard']);
    Route::get('/products', [AdminController::class, 'products']);
});

Testing Routes

You can view all registered routes using the Artisan command:
# List all routes
docker compose exec app php artisan route:list

# List routes with specific name
docker compose exec app php artisan route:list --name=pedido

# List routes with specific path
docker compose exec app php artisan route:list --path=catalogo

Best Practices

Use Named Routes

Always use ->name() to name your routes. This makes refactoring URLs easier.

RESTful Conventions

Follow REST conventions for resource routes (GET, POST, PUT, DELETE).

Route Parameters

Use route parameters instead of query strings for resource identifiers.

Organize with Groups

Use route groups to apply middleware and prefixes to multiple routes.

Future Considerations

As the application evolves, consider:
  • Moving route logic to dedicated controllers
  • Adding authentication middleware for protected routes
  • Implementing route model binding for automatic model injection
  • Adding API routes in routes/api.php for AJAX/SPA functionality
  • Implementing rate limiting for public-facing routes

Build docs developers (and LLMs) love