PHPackages                             stahiralijan/request-caster - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. stahiralijan/request-caster

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

stahiralijan/request-caster
===========================

This package intercepts Laravel Form Submits after successful validation and provides useful function and also casts the submitted form data accordingly e.g. Upper-case first Characters of Words, Capitalized them, and checkbox value "1" to boolean, JSON string to PHP Array conversions etc.

1.1.0(8y ago)13761MITPHPPHP &gt;=7.0

Since Jan 12Pushed 8y ago1 watchersCompare

[ Source](https://github.com/stahiralijan/request-caster)[ Packagist](https://packagist.org/packages/stahiralijan/request-caster)[ RSS](/packages/stahiralijan-request-caster/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (3)Dependencies (2)Versions (4)Used By (0)

Laravel RequestCaster
---------------------

[](#laravel-requestcaster)

[![Latest Stable Version](https://camo.githubusercontent.com/99fb0738fdab51a0fd05fa58d68945e3efd80b732404a3f9e48e4fed8bbaaad8/68747470733a2f2f706f7365722e707567782e6f72672f737461686972616c696a616e2f726571756573742d6361737465722f76657273696f6e)](https://packagist.org/packages/stahiralijan/request-caster)[![Total Downloads](https://camo.githubusercontent.com/cea1012aed2ddccc87e513c3f6a2036f65166a4077decfbe8cca4ca8b11cae0e/68747470733a2f2f706f7365722e707567782e6f72672f737461686972616c696a616e2f726571756573742d6361737465722f646f776e6c6f616473)](https://packagist.org/packages/stahiralijan/request-caster)[![Latest Unstable Version](https://camo.githubusercontent.com/713e47b1c5bf4a6eac177215ef69413adf402c3f5c99f15bad6ff2baf7a8f2cf/68747470733a2f2f706f7365722e707567782e6f72672f737461686972616c696a616e2f726571756573742d6361737465722f762f756e737461626c65)](//packagist.org/packages/stahiralijan/request-caster)[![License](https://camo.githubusercontent.com/985dacad63cf2a232722024f8bb19b6deb25cdcbfe92c67fc245a1c147eda01a/68747470733a2f2f706f7365722e707567782e6f72672f737461686972616c696a616e2f726571756573742d6361737465722f6c6963656e7365)](https://packagist.org/packages/stahiralijan/request-caster)[![Monthly Downloads](https://camo.githubusercontent.com/50aa2941f253441dcdf25c692db48d90ccfda2c6b9c809d874cf6452a82de62b/68747470733a2f2f706f7365722e707567782e6f72672f737461686972616c696a616e2f726571756573742d6361737465722f642f6d6f6e74686c79)](https://packagist.org/packages/stahiralijan/request-caster)[![Daily Downloads](https://camo.githubusercontent.com/03222235f42b50e12de143e7363fe7be68f0eb49af0245f600697a107349782b/68747470733a2f2f706f7365722e707567782e6f72672f737461686972616c696a616e2f726571756573742d6361737465722f642f6461696c79)](https://packagist.org/packages/stahiralijan/request-caster)

*Requirements: I've only tested this package with Laravel 5.5, please help me by testing this package in older versions of Laravel*

### Installation

[](#installation)

Install this package by typing the following command:

```
composer require stahiralijan/request-caster
```

### Usage

[](#usage)

Let's learn from an example:

You want to be able to save the submitted data but you don't want to make a mess in the controller method like this:

```
public function store(UserFormRequest $request)
{
    ...
    $first_name = ucfirst($request->first_name); // or ucfirst($request->get('first_name')
    $last_name = ucfirst($request->last_name); // or ucfirst($request->get('last_name')
    ...
    $user = User::create([
        ...
        'first_name' => $first_name,
        'last_name' => $last_name,
        ...
    ]);
    ...
    // after handling model stuff
    return redirect(route('users.index'))
            ->with('message'=>"User ({$user->first_name} {$user->last_name}) created!");
}
```

As you can see after a while you start to wondering what if there is a way you could automate this process so that your controller would look elegant and clean. With this package you can just do that:

### Step 1:

[](#step-1)

Use the `RequestCaster` Trait in your form request (in this case `UserFormRequest`):

```
...
use Stahiralijan\RequestCaster\Traits\RequestCasterTrait;
...
class UserFormRequest extends FormRequest
{
    use RequestCasterTrait;
    ...
}
```

### Step 2:

[](#step-2)

Define the Request attributes that are required to be casted:

```
class UserFormRequest extends FormRequest
{
    use RequestCasterTrait;

    protected $toUCFirstWords = ['first_name','last_name'];

    // More about this is explained below
    protected $joinStrings = ['fullname'=>' |first_name,last_name'];
    ...
}
```

### Finally

[](#finally)

...and that's all you needed to do, `first_name` and `last_name` are automatically capitalized. Also, you don't need to worry about your form data being getting dirty before validation because these castings will run after the validator validates the form data.

```
public function store(UserFormRequest $request)
{
    // first_name and last_name
    $user = User::create($request->all());
    ...
    // after handling model stuff
    return redirect(route('users.index'))
            ->with('message'=>"User ({$request->full_name}) created!");
}
```

### Available transformations / Casts

[](#available-transformations--casts)

The following casts are available:

- `$toLowerCaseWords`: Applies `strtolower()` to the selected field(s).
- `$toUpperCaseWords`: Applies `strtoupper()` to the selected field(s).
- `$toUCFirstWords`: Applies `ucwords()` to the selected field(s).
- `$toSlugs`: Applies `str_slug()` to the selected field(s).
- `$toIntegers`: Casts selected field(s) to `int`.
- `$toFloats`: Casts selected field(s) to `float`.
- `$toBooleans`: Casts selected field(s) to `bool`.
- `$toArrayFromJson`: Applies `json_decode()` to the selected fields.
- `$joinStrings`: Joins two or more fields and sets the result in new field specified in the array key, syntax: `$joinStrings = ['newField' => 'glue|field1,field2,...,fieldn']`

### Available methods

[](#available-methods)

- `collection(array $keys)` returns an object of `Illuminate\Support\Collection`
- `dd()` dumps and dies all the fields submitted in request
- `dump()` dumps all the fields submitted in request

You can use this method to get a collection (`Illuminate\Support\Collection`) of all the attributes

```
public function store(UserFormReques $request)
{
    $request->collection()->filter(function($item){
        ...
    });
    // or
    $request->collection()->map(function($item){
        ...
    });
}
```

### How to cast

[](#how-to-cast)

All of the properties are pretty straight forward, you define the attributes that needs to be casted like this:

```
// Convert the defined attributes to Upper-case
$toUpperCaseWords = ['product_code'];

// Upper-case the first letter of the words defined below
$toUCFirstWords = ['display_name'];

// Convert the following attributes into slugs
$toSlugs = ['product_name'];
```

You got the idea about the usage of the simple stuff, now one special transformation / caster

```
$joinStrings = ['fullname'=>' |first_name,last_name'];
```

- Here `fullname` will be a new attribute of the `FormRequest` which does not exists in the either the form or the FormRequest in the current context.
- Notice a space `' '` in the starting of value is the glue of the two attributes
- Next `|` is the separator between the glue and the desired attributes
- Next you add the attributes that needs to be glued.

If `first_name` is `Tahir` and `last_name` is `Jan` the output will be `Tahir Jan` according to the above rule, and can be accessed with `$request->fullname` or `$request->get('fullname')`

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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 ~1 days

Total

3

Last Release

3088d ago

Major Versions

0.0.1 → 1.0.22018-01-12

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5305102?v=4)[Syed Tahir Ali Jan](/maintainers/stahiralijan)[@stahiralijan](https://github.com/stahiralijan)

---

Top Contributors

[![stahiralijan](https://avatars.githubusercontent.com/u/5305102?v=4)](https://github.com/stahiralijan "stahiralijan (15 commits)")

---

Tags

laravelphplaravel

### Embed Badge

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

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[renatomarinho/laravel-page-speed

Laravel Page Speed

2.5k1.7M11](/packages/renatomarinho-laravel-page-speed)[vinkius-labs/laravel-page-speed

Laravel Page Speed

2.5k9.6k1](/packages/vinkius-labs-laravel-page-speed)[emargareten/inertia-modal

Inertia Modal is a Laravel package that lets you implement backend-driven modal dialogs for Inertia apps.

90128.1k](/packages/emargareten-inertia-modal)[linkxtr/laravel-qrcode

A clean, modern, and easy-to-use QR code generator for Laravel

3614.9k](/packages/linkxtr-laravel-qrcode)[wearepixel/laravel-cart

A cart implementation for Laravel

1355.6k](/packages/wearepixel-laravel-cart)

PHPackages © 2026

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