Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Telescope not working on a fresh install (wrong path)

Tags:

php

laravel

I am using XAMPP and I installed a fresh Laravel 5.8 with composer create-project --prefer-dist laravel/laravel larascopy in C:\xampp\htdocs\larascopy

I can access it by going to: http://localhost/larascopy/public/

And then installed Telescope with these commands from the Guide:

composer require laravel/telescope
php artisan telescope:install
php artisan migrate

Then I can open Telescope like this http://localhost/larascopy/public/telescope

But all the links are wrong! They are pointing to: http://localhost/telescope/...

So I get all these errors in Console..

POST http://localhost/telescope/telescope-api/commands?tag=&before=&take=50&family_hash= 404 (Not Found)
POST http://localhost/telescope/telescope-api/commands?tag=&before=&take=50&family_hash= 404 (Not Found)
POST http://localhost/telescope/telescope-api/schedule?tag=&before=&take=50&family_hash= 404 (Not Found)
app.js?id=8776cf12ba6d7c72f145:1 Uncaught (in promise) Error: Request failed with status code 404

Is there a way to tell telescope the correct path?

like image 322
Liga Avatar asked May 14 '19 11:05

Liga


Video Answer


2 Answers

I finally found a solution (for anyone else who might come across this issue).

  1. Open: \vendor\laravel\telescope\resources\views\layout.blade.php
  2. Change these lines
<!-- Global Telescope Object -->
<script>
   window.Telescope = @json($telescopeScriptVariables);
</script>

to this

<!-- Global Telescope Object -->
<script>
   window.Telescope = @json($telescopeScriptVariables);
   window.Telescope.path = 'your_project_folder/public/telescope';
</script>
like image 146
Liga Avatar answered Oct 06 '22 11:10

Liga


You need to change Telescope path by overriding telescope layout, for that you need to follow some steps as given below.

This solution is also work for telescope laravel project created in sub-folders.

Step 1: Copy layout file from following path
File Path: project_directory/vendor/laravel/telescope/resources/views/layout.blade.php

Step 2: Paste that copied file to following path
File Path: project_directory/resources/views/vendor/telescope/layout.blade.php

You need to create vendor/telescope folder in resources/views directory.

Step 3: Change layout.blade.php file
File Path: project_directory/resources/views/vendor/telescope/layout.blade.php

Original:

<!-- Global Telescope Object -->
<script>
    window.Telescope = @json($telescopeScriptVariables);
</script>

Updated:

<!-- Global Telescope Object -->
<script>
    window.Telescope = @json($telescopeScriptVariables);

    var telescopePath = "{{ ltrim(parse_url(url(config('telescope.path')))['path'], '/') }}";
    window.Telescope.path = telescopePath;
</script>
like image 27
Milan Katariya Avatar answered Oct 06 '22 12:10

Milan Katariya