PHPackages                             folded/request - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. folded/request

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

folded/request
==============

Request utilities, including a request validator, for your PHP web app.

v0.3.3(5y ago)014MITPHPPHP &gt;=7.4.0

Since Sep 6Pushed 5y ago1 watchersCompare

[ Source](https://github.com/folded-php/request)[ Packagist](https://packagist.org/packages/folded/request)[ RSS](/packages/folded-request/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (6)Versions (7)Used By (0)

folded/request
==============

[](#foldedrequest)

Request utilities, including a request validator, for your PHP web app.

[![Packagist License](https://camo.githubusercontent.com/b40a3eca6cda972cb881da83c48ebd559dbd3b90638627eed4e691cf4d07d7fc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f666f6c6465642f72657175657374)](https://github.com/folded-php/request/blob/master/LICENSE) [![Packagist PHP Version Support](https://camo.githubusercontent.com/fd29c7550661f64f6f41e85c24c8ba0b59b9912d31edcbd3eff0736213f96755/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f666f6c6465642f72657175657374)](https://github.com/folded-php/request/blob/master/composer.json#L14) [![Packagist Version](https://camo.githubusercontent.com/83d530b813f173930bfc286bf4a89e66fbe95d9bf469f84dcb93826ce9cca059/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666f6c6465642f72657175657374)](https://packagist.org/packages/folded/request) [![Build Status](https://camo.githubusercontent.com/b6cf40564d187a19d1cc481c8ec2a9efe94313fcf51f2630f68cc4757011fa61/68747470733a2f2f7472617669732d63692e636f6d2f666f6c6465642d7068702f726571756573742e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/folded-php/request) [![Maintainability](https://camo.githubusercontent.com/6611a1cadb7f390fe7c923686be69cc1c93a378e213e75ab28e986e7d0688cd9/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f61303063653239613562353439643666326261342f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/folded-php/request/maintainability) [![TODOs](https://camo.githubusercontent.com/2b59f2b414bd45fcd01ac4c16e91da3b85c6761b01b9ba5ccbe20a9d6a89748c/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f75726c3d68747470733a2f2f6170692e7469636b6769742e636f6d2f62616467653f7265706f3d6769746875622e636f6d2f666f6c6465642d7068702f72657175657374)](https://www.tickgit.com/browse?repo=github.com/folded-php/request)

Summary
-------

[](#summary)

- [About](#about)
- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Examples](#examples)
- [Version support](#version-support)

About
-----

[](#about)

I need a way to pull a simple library to validate my request data when a form is submited. This library hopefuly solves this by faciliting the set up to be ready to validate request values.

Folded is a constellation of packages to help you setting up a web app easily, using ready to plug in packages.

- [folded/action](https://github.com/folded-php/action): A way to organize your controllers for your web app.
- [folded/config](https://github.com/folded-php/config): Configuration and environment utilities for your PHP web app.
- [folded/crypt](https://github.com/folded-php/crypt): Encrypt and decrypt strings for your web app.
- [folded/exception](https://github.com/folded-php/exception): Various kind of exception to throw for your web app.
- [folded/history](https://github.com/folded-php/history): Manipulate the browser history for your web app.
- [folded/http](https://github.com/folded-php/http): HTTP utilities for your web app.
- [folded/orm](https://github.com/folded-php/orm): An ORM for you web app.
- [folded/routing](https://github.com/folded-php/routing): Routing functions for your PHP web app.
- [folded/session](https://github.com/folded-php/session): Session functions for your web app.
- [folded/view](https://github.com/folded-php/view): View utilities for your PHP web app.

Features
--------

[](#features)

- Can get GET or POST request data
- Can check if a key is present in GET or POST data
- Can validate request (using Laravel's validation request utilities)
- Can check if the request validation succeeded
- Can get the (translated) errors when the request validation failed

Requirements
------------

[](#requirements)

- PHP version &gt;= 7.4.0
- Composer installed

Installation
------------

[](#installation)

- [1. Install the package](#1-install-the-package)
- [2. Set up the library](#2-set-up-the-library)

### 1. Install the package

[](#1-install-the-package)

In your root folder directory, run this command:

```
composer require folded/request
```

### 2. Set up the library

[](#2-set-up-the-library)

If you want to use the request validation functions, use this code before validating your form data:

```
use function Folded\setRequestValidationTranslationFolderPath;

setRequestValidationTranslationFolderPath(__DIR__ . "/lang");
```

The lang folder should contain an arborescence made of folders named with the lang (like "en", "fr", "es", ...), which themselves contain a file named `validation.php` containing the translation of the validation error message.

As this library relies on Laravel's validation system, the validation errors messages are pulled from these files.

Here is [the content](https://github.com/laravel/laravel/blob/v7.25.0/resources/lang/en/validation.php) of `en/validation.php` for example. You can start from this file to create translation for other languages.

Examples
--------

[](#examples)

- [1. Get a request value by its key](#1-get-a-request-value-by-its-key)
- [2. Check if a request key is present](#2-check-if-a-request-key-is-present)
- [3. Get all the request values](#3-get-all-the-request-values)
- [4. Validate a request](#4-validate-a-request)
- [5. Check if a request validation succeeded](#5-check-if-a-request-validation-succeeded)
- [6. Get error messages after a request validation](#6-get-error-messages-after-a-request-validation)
- [7. Choosing the validation error language before validating request](#7-choosing-the-validation-error-language-before-validating-request)
- [8. Get an old submited form value](#8-get-an-old-submited-form-value)

### 1. Get a request value by its key

[](#1-get-a-request-value-by-its-key)

In this example, we will get the value of a request key after a post request has been submitted.

```
use function Folded\getRequestValue;

echo getRequestValue("name");
```

### 2. Check if a request key is present

[](#2-check-if-a-request-key-is-present)

In this example, we will check first if a key is present before echoing its content.

```
use function Folded\getRequestValue;
use function Folded\hasRequestValue;

if (hasRequestValue("name")) {
  echo getRequestValue("name");
} else {
  echo "Request does not have key name.";
}
```

### 3. Get all the request values

[](#3-get-all-the-request-values)

In this example, we will get all the request value key-pairs in an array.

```
use function Folded\getAllRequestValues;

$values = getAllRequestValues();

foreach ($values as $name => $value) {
  echo "Post value for $name is $value";
}
```

### 4. Validate a request

[](#4-validate-a-request)

In this example, we will validate form request data.

```
use function Folded\validateRequest;

validateRequest([
  "name" => "required|filled",
]);
```

For more information about the available validation, check [Laravel's validation documentation](https://laravel.com/docs/7.x/validation#available-validation-rules), as this library relies on this system.

### 5. Check if a request validation succeeded

[](#5-check-if-a-request-validation-succeeded)

In this example, we will check if a request succeeded after validating it.

```
use function Folded\validateRequest;
use function Folded\requestValidationSucceeded;

validateRequest([
  "name" => "required|filled",
]);

if (requestValidationSucceeded()) {
  echo "it worked!";
} else {
  echo "some errors occured...";
}
```

### 6. Get error messages after a request validation

[](#6-get-error-messages-after-a-request-validation)

In this example, we will get the errors messages of a failed request validation.

```
use function Folded\validateRequest;
use function Folded\requestValidationSucceeded;
use function Folded\getRequestValidationErrors;

validateRequest([
  "email" => "required|filled",
]);

if (!requestValidationSucceeded()) {
  $errors = getRequestValidationErrors();

  foreach ($errors as $error) {
    echo "error: {$error->message()}";
  }
}
```

For more information about how to manipulate the errors, see [Laravel's validation error documentation](https://laravel.com/docs/7.x/validation#working-with-error-messages), as this library relies on this system.

### 7. Choosing the validation error language before validating request

[](#7-choosing-the-validation-error-language-before-validating-request)

In this example, before validating the request, we will change the language for the validation erorrs. Note that you should do it ideally right after the code from the Installation section: [2. Set up the library](#2-set-up-the-library) section.

```
use function Folded\setRequestValidationLang;
use function Folded\setRequestValidationTranslationFolderPath;

setRequestValidationTranslationFolderPath(__DIR__ . "/lang");
setRequestValidationLang("fr");
```

### 8. Get an old submited form value

[](#8-get-an-old-submited-form-value)

In this example, we will get a previously submitted form value. This is convenient if you want to display values the user used before an error occured (in order for the user to not loose everything he wrote).

```
use function Folded\storeOldRequestValues;
use function Folded\getOldRequestValue;

// Session must be enabled to make it work
session_start();

// As soon as possible
storeOldRequestValues();

// Get the old form values, assuming you previously listened a POST request with an email key
echo getOldRequestValue("email");
```

If the key is not found, the `getOldRequestValue()` function returns `null`.

Version support
---------------

[](#version-support)

7.37.48.0v0.1.0❌✔️❓v0.2.0❌✔️❓v0.3.0❌✔️❓v0.3.1❌✔️❓v0.3.2❌✔️❓v0.3.3❌✔️❓

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~5 days

Total

6

Last Release

2053d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15908747?v=4)[Anwar](/maintainers/khalyomede)[@khalyomede](https://github.com/khalyomede)

---

Top Contributors

[![khalyomede](https://avatars.githubusercontent.com/u/15908747?v=4)](https://github.com/khalyomede "khalyomede (35 commits)")

---

Tags

laravelphprequest-validation

###  Code Quality

TestsPest

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/folded-request/health.svg)

```
[![Health](https://phpackages.com/badges/folded-request/health.svg)](https://phpackages.com/packages/folded-request)
```

###  Alternatives

[spatie/laravel-honeypot

Preventing spam submitted through forms

1.6k6.0M60](/packages/spatie-laravel-honeypot)[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k35.7M107](/packages/propaganistas-laravel-phone)[proengsoft/laravel-jsvalidation

Validate forms transparently with Javascript reusing your Laravel Validation Rules, Messages, and FormRequest

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[wendelladriel/laravel-validated-dto

Data Transfer Objects with validation for Laravel applications

759569.4k13](/packages/wendelladriel-laravel-validated-dto)[intervention/validation

Additional validation rules for the Laravel framework

6826.7M8](/packages/intervention-validation)[axlon/laravel-postal-code-validation

Worldwide postal code validation for Laravel and Lumen

3853.3M1](/packages/axlon-laravel-postal-code-validation)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
