Download the PHP package alvarofpp/expand-request without Composer
On this page you can find all versions of the php package alvarofpp/expand-request. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alvarofpp/expand-request
More information about alvarofpp/expand-request
Files in alvarofpp/expand-request
Package expand-request
Short Description A package to make it easy to manipulate your requests and more
License MIT
Homepage https://github.com/alvarofpp/laravel-expand-request
Informations about the package expand-request
expand-request
A package to make it easy to manipulate your requests and more.
Contents
- Install
- Usage
- Contributing
Install
Install via composer:
Usage
This package currently contains:
- Checks whether the request url belongs to a pattern.
- Add url parameters to be validated.
- Rename url parameters.
- Remove extra parameters.
Checks whether the current request url belongs to a pattern
You can check whether the request url belongs to a url pattern or route pattern. Use this methods:
is_url($patterns, $request = null)
is_route($patterns, $request = null)
By default, $request
is the current request.
Example: You can use this to activate a class in your menu, such as:
These methods accept a array as the first parameter, so that you can check various patterns:
Another example is that you can use it to check where the user is coming from:
UrlParameters
Add url parameters to be validated in your FormRequest.
Use the trait UrlParameters
in your FormRequest, such as:
If your url is [GET] /courses/{course}
,
you can validate the parameter course
in your $rules
:
Rename url parameters
If you want rename the parameter, just declare the variable $renameUrlParameters
.
Example: you have a url /courses/{course}/contents/{content}/videos/{video}
, you can use:
Declare the index in the array to decide which parameter will change:
Remove extra parameters
Use the trait RemoveExtraParameters
in your FormRequest to remove extra parameters:
This trait uses the $accept
property. By default the values in $accept
are a merge of the keys present in rules()
and attributes()
. You can specify which fields are accepted in your FormRequest specifying in $accept
.
In this example, if you receive a request such as {"field_1": 50, "field_2": 100, "extra_field": 1}
, the extra_field
will be removed from that request.
Contributing
Contributions are more than welcome. Fork, improve and make a pull request. For bugs, ideas for improvement or other, please create an issue.