ge-tracker / octane-helpers
Helper code for Laravel Octane
v1.0.1
2023-03-06 12:04 UTC
Requires
- php: ^8.0
- illuminate/support: ^8.0|^9.0|^10.0
- laravel/octane: ^1.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.6
- gtjamesa/php-standards: ^2.0
- orchestra/testbench: ^6.0|^7.0|^8.0
- phpunit/phpunit: ^9.0
README
This package will provide some basic functionality to our various Laravel Octane projects.
Installation
$ composer require ge-tracker/octane-helpers
After installation, the BootApplication
class should be added to the RequestReceived
listener in octane.php
:
'listeners' => [ ... RequestReceived::class => [ ...Octane::prepareApplicationForNextOperation(), ...Octane::prepareApplicationForNextRequest(), \GeTracker\OctaneHelpers\Listeners\BootApplication::class, ],
Routing
We can make use of Octane's builtin routing to serve requests that bypass Laravel's router (and middleware) to serve data very fast.
With a basic controller that extends OctaneController
:
<?php namespace GeTracker\OctaneHelpers\Http\Controllers; class ServerTimeController extends OctaneController { public function getServerTime() { return time(); } }
We can add the following to our web.php
routes file:
<?php use GeTracker\OctaneHelpers\Facades\OctaneRoute; OctaneRoute::get('/api/server-time', [ServerTimeController::class, 'getServerTime']);