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
Requires
- php: ^8.0
- illuminate/routing: >=11.46.1
- illuminate/support: >=11.46.1
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.