Closed
Description
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
- Open Laravel Tinker (
sail tinker
/php artisan tinker
) - 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
Labels
No labels