fruitcake / laravel-telescope-toolbar

A toolbar for Laravel Telescope, based on the Symfony Web Profiler.
MIT License
772 stars 36 forks source link

Laravel Octane support #58

Open osbre opened 2 years ago

osbre commented 2 years ago

Tried to register it in the flush section, still shows first request all the time.

'flush' => [
    Fruitcake\TelescopeToolbar\ToolbarServiceProvider::class,
],
osbre commented 2 years ago

The possible problem is that this method always has the same $token value:

https://github.com/fruitcake/laravel-telescope-toolbar/blob/baa455f6c51659e644212d5a9e23e5d7ca3bb2a6/src/Toolbar.php#L201

bornemisza commented 6 months ago

I have found an "issue" which is Laravel Octane related, but not similar to the original issue.

If somone using start kit and installs the Octane and Toolbar as well, but not running view:clear, before starting Octane the first time, will found it self, that the icons are not loaded, just the @ttIcon directive is shown. The main "issue" is that Octane automatically caches the views. (It does not make a difference, if you use the file watching option on Octane.) While running the Octane you cannot clear the view cache, so you have to stop the server first and clear the view cache after. If you clear the cache and start again the Octane server, the icons will appear now.

I'm not 100% sure, if the Toolbar should handle the view cache clearing when Octane is used, but I just thought maybe it'll help someone else if experiencing this icon problem.

Viktor-V commented 4 months ago

@bornemisza Thank you for your solution, but unfortunately it didn't help me. Here's my solution that I hope will help others who have encountered the same issue:

  1. Create a new provider
    
    <?php

declare(strict_types=1);

namespace App\Providers;

use Illuminate\Support\Facades\Blade; use Illuminate\Support\ServiceProvider;

class TelescopeToolbarServiceProvider extends ServiceProvider { public function register(): void { // }

public function boot(): void
{
    Blade::directive('ttIcon', static function ($expression) {
        $dir = \realpath(__DIR__ . '/../../vendor/fruitcake/laravel-telescope-toolbar/resources/icons');
        return "<?php echo file_get_contents('$dir/' . basename($expression) . '.svg'); ?>";
    });
}

}


2. Register it in bootstrap/providers.php
```php
<?php

return [
    App\Providers\AppServiceProvider::class,
    App\Providers\TelescopeServiceProvider::class,
    App\Providers\TelescopeToolbarServiceProvider::class,
];

P.S. I've only tested this on Laravel 11