kmuenkel / route-injection
Allow for Laravel Controller method injection of *any* object type.
v1.0.8
2020-12-06 02:00 UTC
Requires
- illuminate/http: ^7.0|^8.0
- illuminate/routing: ^7.0|^8.0
- illuminate/support: ^7.0|^8.0
Requires (Dev)
- barryvdh/laravel-ide-helper: ^2.8
- friendsofphp/php-cs-fixer: ^2.16
- fzaninotto/faker: ^1.9
- mockery/mockery: ^1.4
- orchestra/testbench: ^5.7
- phpmd/phpmd: ^2.9
- phpunit/phpunit: ^9.4
- squizlabs/php_codesniffer: ^3.5
README
Inspired by Laravel's Route Model Binding, this package takes that a step further, and allows for Controller method injection of any object type.
- Activate the
RouteInjection\Providers]RouteInjectionServiceProvider
by either adding it to yourapp.php
config, or making sure yourcomposer.json
file includes the@php artisan package:discover --ansi
script. - Create a class designed to parse an incoming
Request
and produce a concrete object that will be injected into the controller. To do this, simply extend theRouteInjection\Binder
class. - Reference your custom
Binder
class name in theroute-injection
config array. - Ensure that your routes leverage Laravel's
SubstituteBindings
middleware. This should be automatic in your 'api' and 'web' routes, but any outside of these groups may need to have it explicitly listed among its middleware configs.