Skip to content

route() helper does not URL-encode route parameters #57898

Closed

Description

@miken32

Laravel Version

12.37.0

PHP Version

8.4.14

Database Driver & Version

No response

Description

I was surprised to find out that this function does not URL-encode passed parameters for me. I'm now having to go through my codebase and manually encode things, after an un-encoded value sent users to an invalid URL.

At the very least, the documentation should mention this shortcoming.

Ideally, a fourth argument would be added to route() to enable proper URL encoding. Something like:

function route(
    BackedEnum|string $name, 
    mixed $parameters, 
    bool $absolute = true, 
    bool $encode_params = false
): string

Steps To Reproduce

Route::get('/e/{data}')->name('test');

echo route('test', ['data' => 'foo/bar']);

Result: /e/foo/bar

Expected result: /e/foo%2fbar

Activity

  1. locked and limited conversation to collaborators on Nov 24, 2025
  2. converted this issue into a discussion #57899 on Nov 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions