faintshadow/routehelper

Generate a URL pattern for a named route with placeholder support.

Installs: 11

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Forks: 0

pkg:composer/faintshadow/routehelper

1.0.2 2025-10-04 12:46 UTC

This package is not auto-updated.

Last update: 2026-01-10 16:18:38 UTC


README

Generate a URL pattern for a named route with placeholder support.

This helper creates route URLs with placeholder templates that can be used for frontend JavaScript route generation. Placeholders MUST follow the format {name} where 'name' matches the route parameter name.

Examples:

Basic usage with placeholder:

$pattern = routeTemplate('company.item.destroy', [
    'company' => $company->id,
    'item' => '{item}'  // MUST use {item} format
]);
// Returns: "https://example.com/companies/123/items/{item}"

Usage with multiple placeholders:

$pattern = routeTemplate('company.department.employee.show', [
    'company' => '{company}',      // MUST use {company} format
    'department' => '{department}', // MUST use {department} format
    'employee' => '{employee}'      // MUST use {employee} format
]);

Mixed actual values and placeholders:

$pattern = routeTemplate('company.item.edit', [
    'company' => 456,        // Actual value
    'item' => '{item}'       // Placeholder - MUST use {item} format
]);
// Returns: "https://example.com/companies/456/items/{item}/edit"

Important:

All placeholder templates MUST follow the exact format {parameterName} where parameterName matches the route parameter. Incorrect formats like {{item}}, <item>, or ITEM_ID will not work.