Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Uri helper cannot be "fluently modified" when starting with just the path #55818

Copy link
Copy link
Closed
@KSneijders

Description

@KSneijders
Issue body actions

Laravel Version

12.14.1

PHP Version

8.4.7

Database Driver & Version

No response

Description

The Uri helper cannot be "fluently modified" (as shown in the docs) when starting with a relative url (path only)

This will return errors due to the fluent changes happening one at a time, all resulting in invalid states. (Although adding a Host to a Uri with just path should result in a valid state).

Steps To Reproduce

  1. Open Laravel Tinker (sail tinker / php artisan tinker)
  2. Run the following:
use Illuminate\Support\Uri;

$uri = Uri::of('relative/path/to/resource');

dump($uri);  /* Viewing contents of current URI */

/* 
 * Scheme first, Host second:
 *   League\Uri\Exceptions\SyntaxError: The uri `https:relative/path/to/resource` is invalid for the `https` scheme. 
 */
$uri->withScheme('https')->withHost('example.com')->withPath('/other/path/to/resource');

/* 
 * Alternatively, Host first, Scheme second:
 *   League\Uri\Exceptions\SyntaxError: If an authority is present the path must be empty or start with a `/`.
 */
$uri->withHost('example.com')->withScheme('https')->withPath('/other/path/to/resource');

Now if this is not supported that's fine, but it is very unintuitive as you can create (and work with other parts of) the created Uri when only supplying a relative URL.

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.