-
-
Notifications
You must be signed in to change notification settings - Fork 478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
It would be really cool if you could add Laravel Octane support for this #193
Comments
you can create middleware, and add it Kernel
|
here is how I solved this: <?php
namespace App\Providers;
use Illuminate\Foundation\Application;
use Illuminate\Support\ServiceProvider;
use Jenssegers\Agent\Agent;
class OctaneServiceProvider extends ServiceProvider
{
private $isRunningInOctane;
public function register()
{
parent::register();
$this->registerBinding('agent', fn (Application $app) => new Agent($app['request']->server()), Agent::class);
}
private function registerBinding(string $name, callable $fn, string $alias): void
{
if ($this->runningInOctane()) {
$this->app->bind($name, $fn, true);
} else {
$this->app->singleton($name, $fn);
}
$this->app->alias($name, $alias);
}
private function runningInOctane(): bool
{
if (is_null($this->isRunningInOctane)) {
$this->isRunningInOctane = !$this->app->runningInConsole() && env('LARAVEL_OCTANE');
}
return $this->isRunningInOctane;
}
} I created my own service provider to handle those Octane incompatibilities of 3rd party packages in one place. In my real code I use multiple Don't forget to register it in Hope it helps. |
Hi @jangaraev |
I believe that the only reason Octane doesn't work with this is due to the way how request injection works through the service provider. See https://laravel.com/docs/8.x/octane#request-injection
Basically... the current code always leaves the user agent null.
The text was updated successfully, but these errors were encountered: