Download the PHP package soyhuce/laravel-model-injection without Composer
On this page you can find all versions of the php package soyhuce/laravel-model-injection. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download soyhuce/laravel-model-injection
More information about soyhuce/laravel-model-injection
Files in soyhuce/laravel-model-injection
Package laravel-model-injection
Short Description Extended Model injection for Laravel
License MIT
Homepage https://github.com/soyhuce/laravel-model-injection
Informations about the package laravel-model-injection
Extended Model injection for Laravel
Want to control have better control of model injection ? Need to validate the data before querying the database ?
Here is a package that allows you to do that.
Installation
You can install the package via composer:
Usage
Implicit binding
To validate the url parameter used to inject the model in the controller, you can use
the Soyhuce\ModelInjection\ValidatesImplicitBindings
trait in it.
You will have then to implement the method public function routeBindingRules(): array
which will define, for each key on which the model will be bound, the rules to validate the url parameter.
This will allow you to validate the parameter to bind the Post
in the routes using:
If the parameter is not valid, a 404 error will be returned.
See https://laravel.com/docs/routing#implicit-binding
Customize implicit route binding error
You can customize the way this package will handle validation failure for implicit bindings.
In a Service provider, just call InvalidRouteBinding::handleUsing
:
Explicit bindings
You can explicitly bind your models using \Soyhuce\ModelInjection\BindModels
trait in a service
provider (RouteServiceProvider
for exemple).
If the given parameter is not valid, a 404 error will be returned.
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Bastien Philippe
- All Contributors
License
The MIT License (MIT). Please see License File for more information.