kmuenkel / route-injection
Allow for Laravel Controller method injection of *any* object type.
Installs: 261
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/kmuenkel/route-injection
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]RouteInjectionServiceProviderby either adding it to yourapp.phpconfig, or making sure yourcomposer.jsonfile includes the@php artisan package:discover --ansiscript.
- Create a class designed to parse an incoming Requestand produce a concrete object that will be injected into the controller. To do this, simply extend theRouteInjection\Binderclass.
- Reference your custom Binderclass name in theroute-injectionconfig array.
- Ensure that your routes leverage Laravel's SubstituteBindingsmiddleware. 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.