@bzarboni I'd say you have two options here. First one being to fork the packages repository, make your changes, and then have your composer install via your forked repository instead of the original.
Second option being a bit more complicated. Typically you should utilize the container to override/extend vendor packages, however the class in question you are trying to override, is directly instantiated in debugbar's core class, thus you cannot directly swap it out through the container.
https://github.com/barryvdh/laravel-debugbar/blob/master/src/LaravelDebugbar.php#L659
What you can do however, is redeclare the singleton binding for LaravelDebugbar to your own custom class extending the packages concrete class, and overwrite the getJavascriptRenderer method to return your extended renderer class.
Renderer
<?php
namespace App\Support;
use Barryvdh\Debugbar\JavascriptRenderer as BaseJavascriptRenderer;
class JavascriptRenderer extends BaseJavascriptRenderer
{
public function renderHead()
{
dump('made it');
return parent::renderHead();
}
}
Debugbar Extension
<?php
namespace App\Support;
use App\Support\JavascriptRenderer as JavascriptRendererExtended;
use Barryvdh\Debugbar\LaravelDebugbar;
class DebugBar extends LaravelDebugbar
{
public function getJavascriptRenderer($baseUrl = null, $basePath = null)
{
if ($this->jsRenderer === null) {
$this->jsRenderer = new JavascriptRendererExtended($this, $baseUrl, $basePath);
}
return $this->jsRenderer;
}
}
Then just overwrite the packages binding for LaravelDebugbar in one of your ServiceProvider
<?php
namespace App\Providers;
use App\Support\DebugBar;
use Barryvdh\Debugbar\LaravelDebugbar;
use Barryvdh\Debugbar\SymfonyHttpDriver;
use Illuminate\Session\SessionManager;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->singleton(LaravelDebugbar::class, function ($app) {
$debugbar = new DebugBar($app);
if ($app->bound(SessionManager::class)) {
$sessionManager = $app->make(SessionManager::class);
$httpDriver = new SymfonyHttpDriver($sessionManager);
$debugbar->setHttpDriver($httpDriver);
}
return $debugbar;
});
}
}