PHPackages                             akbarali/action-data - 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. akbarali/action-data

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

akbarali/action-data
====================

Action Data Validate PHP Laravel

1.4.1(1y ago)22871MITPHPPHP &gt;=8.0

Since Jan 31Pushed 1y ago1 watchersCompare

[ Source](https://github.com/akbarali1/action-data)[ Packagist](https://packagist.org/packages/akbarali/action-data)[ RSS](/packages/akbarali-action-data/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (5)Versions (25)Used By (0)

Install
=======

[](#install)

```
composer require akbarali/action-data

```

Instructions for use
====================

[](#instructions-for-use)

Laravel Request Used:

```
StoreIncomeActionData::createFromRequest($request);
```

Array Used:

```
StoreIncomeActionData::createFromArray($array);
```

Json Used:

```
StoreIncomeActionData::createFromJson($json);
```

If you want to add a new validation type between functions

```
$actionData->addValidationRule('id', 'required|integer');
//To check again
$actionData->validateException();
```

Let's say you have data in array type. You can also add value to it yourself. For example:

```
$userId = Auth::id();
$actionData->set('data', '*.user_id', $userId);
$actionData->addValidationRule('data.*.user_id', 'required|integer');
$actionData->validateException();
```

ActionData get Array

```
$actionData->toArray();
// or
$actionData->all();
// or
$actionData->toSnakeArray();
```

If you only need some of that class

```
$actionData->only(['id', 'name']);
```

If you want direct access in Laravel Controller, add it to `providers` in `/config/app.php`

```
'providers' => [
...
\Akbarali\ActionData\Providers\ActionDataServiceProvider::class,
]
```

Then you can use the ActionData class in the Controller function Example:

```
public function store(StoreIncomeActionData $actionData)
{
//This includes validated information. Otherwise, it returns an ActionDataException.
}
```

0.8 version
===========

[](#08-version)

Add `isUpdate()` method

```
if($actionData->isUpdate()){
// Update
}else{
// Create
}
```

1.0.0 version
=============

[](#100-version)

Added `setUser` `isCreate` `getUser` `updated` `created` `fromRequest` and `fromArray` methods

`setUser` method is used to set

```
class StorePotentialPartnersActionData extends \Akbarali\ActionData\ActionDataBase
{
    public ?int    $id;
    public ?int    $agent_id;
    public ?string $phone;

    public ?string $full_name;
    public ?string $address;
    public ?string $description;
    /** @var array|null */
    public ?array $images    = [];
    public ?array $oldImages = [];

    protected function prepare(): void
    {
        $this->rules = [
            'id'          => 'nullable|numeric|exists:potential_partner,id',
            'full_name'   => 'required',
            'address'     => 'required',
            'description' => 'nullable',
            "images"      => "required_without:oldImages|array",
            "images.*"    => "required|image",
            "oldImages"   => "required_without:images|array",
            "oldImages.*" => "required|int|exists:potential_partner_images,id",
        ];
    }

    protected function setUser(): void
    {
        $this->user = auth()->user();
    }
}
```

`updated` method means that it is an update operation.

```
/**
 * @param int     $id
 * @param Request $request
 * @return RedirectResponse
 * @throws ValidationException
 */
public function update(int $id, Request $request): RedirectResponse
{
   try {
        $request->request->set('id', $id);
        $this->storePotentialPartner(StorePotentialPartnersActionData::fromRequest($request)->updated());
        return to_route('page.index')->with('message', trans('all.updated'));
    } catch (OperationException|ActionDataException|QueryException $e) {
        return back()->withInput()->withErrors($e->getMessage());
   }
}
```

If you do not call `->updated()` after `fromRequest`, it will automatically check by id. If the id is in your request, then it knows that it is an update operation

That's how it's written:

```
public function isUpdate(): bool
{
    return $this->updated ?? (isset($this->id) && $this->id > 0);
}
```

`created()` is the opposite of `->updated()`

`fromRequest` to reference `createFromRequest` method `fromArray` to reference `createFromArray` method

1.0.1 version
=============

[](#101-version)

readonly supported

```
class StorePartnersActionData extends \Akbarali\ActionData\ActionDataBase
{
    public readonly int $id;

    protected function prepare(): void
    {
        $this->rules = [
            'id'          => 'nullable|numeric|exists:potential_partner,id',
        ];
    }
}

class PartnerController extends Controller{

    public function update(int $id, Request $request): RedirectResponse
    {
       try {
            $request->request->set('id', $id);
            $this->storePartner(StorePartnersActionData::fromRequest($request)->updated());
            return to_route('page.index')->with('message', trans('all.updated'));
        } catch (OperationException|ActionDataException|QueryException $e) {
            return back()->withInput()->withErrors($e->getMessage());
       }
    }

    public function storePartner(StorePotentialPartnersActionData $actionData): RedirectResponse
    {
        $actionData->id = 1; // Exception: Error
    }
}
```

Error: Cannot modify readonly property `App\ActionData\StorePartnersActionData::$id`

1.2.3 version
=============

[](#123-version)

```
$actionData->addValidationRule('pinfl', 'unique:users,pinfl');
$actionData->addValidationRules([
	'pinfl' => 'unique:users,pinfl',
	'phone' => 'unique:users,phone',
	'passport' => 'unique:users,passport',
]);
$actionData->addValidationValue('required', [
	'pinfl', 'passport', 'phone', 'passportIssueDate',
	'firstName', 'lastName', 'middleName', 'docType',
	'card',
]);
```

1.4.0 version
=============

[](#140-version)

Added `fromJson` and bug fix `createFromArray`

###  Health Score

33

—

LowBetter than 77% of packages

Maintenance43

Moderate activity, may be stable

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity56

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

Recently: every ~47 days

Total

23

Last Release

449d ago

Major Versions

0.8.0 → 1.0.02024-04-01

### Community

Maintainers

![](https://www.gravatar.com/avatar/b3228f32e213a2e306db99f2526c4ec31bac09c86e360db37bde696689f962a2?d=identicon)[akbarali](/maintainers/akbarali)

---

Top Contributors

[![akbarali1](https://avatars.githubusercontent.com/u/39323182?v=4)](https://github.com/akbarali1 "akbarali1 (47 commits)")

---

Tags

phplaravel

### Embed Badge

![Health badge](/badges/akbarali-action-data/health.svg)

```
[![Health](https://phpackages.com/badges/akbarali-action-data/health.svg)](https://phpackages.com/packages/akbarali-action-data)
```

###  Alternatives

[yorcreative/laravel-argonaut-dto

Argonaut is a lightweight Data Transfer Object (DTO) package for Laravel that supports nested casting, recursive serialization, and validation out of the box. Ideal for service layers, APIs, and clean architecture workflows.

1042.4k1](/packages/yorcreative-laravel-argonaut-dto)[reducktion/socrates

A package to validate, and extract citizen information from, national identification numbers.

488.4k](/packages/reducktion-socrates)

PHPackages © 2026

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