laravel-telescope-toolbar icon indicating copy to clipboard operation
laravel-telescope-toolbar copied to clipboard

Laravel Octane support

Open osbre opened this issue 2 years ago • 3 comments

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

'flush' => [
    Fruitcake\TelescopeToolbar\ToolbarServiceProvider::class,
],

osbre avatar Dec 22 '21 19:12 osbre

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

osbre avatar Dec 22 '21 20:12 osbre

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.

bornemisza avatar Feb 19 '24 12:02 bornemisza

@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'); ?>";
        });
    }
}
  1. Register it in bootstrap/providers.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

Viktor-V avatar May 06 '24 13:05 Viktor-V