Download the PHP package shahal-hexnine/laravel-request-context without Composer
On this page you can find all versions of the php package shahal-hexnine/laravel-request-context. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download shahal-hexnine/laravel-request-context
More information about shahal-hexnine/laravel-request-context
Files in shahal-hexnine/laravel-request-context
Package laravel-request-context
Short Description Store and access contextual request data with ease
License MIT
Informations about the package laravel-request-context
Store additional contextual data on Laravel Request objects
This package makes managing contextual data about a request a breeze. It might be helpful to think of Request Contexts as an alternative to session data, the difference being Request Contexts only persist for the lifespan of the request.
For example, you can retrieve the authenticated User
's active Team
like so:
Installation
You can install the package via composer:
Note: Laravel 5.4+ is required.
Usage
Register context for later use in the request
Access Request Context by key
Request Contexts don't have to be Eloquent models:
The sky is pretty much the limit. You can even pass an array of contexts in:
Facade & helper
Go ahead, there's no judgement here.
Facade Context
:
Helper method context()
:
Where to bind Contexts?
A Middleware is the perfect candidate:
But why?
Accessing contextual data through chained Eloquent relationships and helpers leaks implementation details throughout your application, and often leads to a lot of similar and repeated lines of code.
This package does its best to aid you in the following ways:
- Explicitly binds contextual data in a single location
- Makes refactoring contextual relationships much easier and less risky
- Context values are easily retrieved anywhere you have access to a
Request
object without memorizing chained eloquent relationships
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
Spatie for their commitment to open source and the Laravel community (and for the skeleton used to create this package!)
License
The MIT License (MIT). Please see License File for more information.