Telescope Version : 5.10
Laravel Version : 10.48.29
PHP Version : 8.3.11
Issue
Laravel runs in a subfolder. This means only urls starting with /foo/ get routed to Laravel’s index.php. Other urls like /telescope/ are out of laravels control. Laravel’s router is smart enough to check that it is in a subforlder and ignores /foo/ in the url when matching routes. As a result the route “/telescope” automatically get converted to “example.com/foo/telescope” when printing routes with route() and the router maps /foo/telescope to telescopes controller. Telescope is not so smart. It takes the path from the config “path” => “telescope” and creates urls starting with “/telescope”. If i change it to “path” => “foo/telescope” Laravel’s router interprets them as “/foo/foo/telescope”. This results in Telescope still being incorrect because its javascript tries to send api requests to “/foo/telescope/telescope-api” but “/foo/foo/telescope/telescope” would be correct.
Quick Fix – Not Working
I’ve tried adding this fix in the bottom part also in header in both cases the path and basePath is going back to /telescope.
@php
$url = parse_url(config('app.url'));
$basePath = isset($url['path']) ? $url['path'] . '/telescope' : 'telescope';
$path = isset($url['path']) ? ltrim($url['path'], '/') . '/telescope' : 'telescope';
$vars = LaravelTelescopeTelescope::scriptVariables();
$vars['basePath'] = $basePath;
$vars['path'] = $path;
@endphp
<script>
window.Telescope = @json($vars);
console.log(window.Telescope.basePath);
console.log(window.Telescope.path);
</script>