PHPackages                             bakome/laravel-validation-attributes - 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. bakome/laravel-validation-attributes

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

bakome/laravel-validation-attributes
====================================

v1.0.1(5y ago)329MITPHPPHP ^8.0

Since Feb 25Pushed 5y ago1 watchersCompare

[ Source](https://github.com/bakome/laravel-validation-attributes)[ Packagist](https://packagist.org/packages/bakome/laravel-validation-attributes)[ Docs](https://github.com/bakome/laravel-validation-attributes)[ RSS](/packages/bakome-laravel-validation-attributes/feed)WikiDiscussions main Synced 3w ago

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

Use PHP 8 attributes to implement request data validation
=========================================================

[](#use-php-8-attributes-to-implement-request-data-validation)

[![Latest Version on Packagist](https://camo.githubusercontent.com/7b9ac677f17b3bc1e54736b1f3993ebe1a189551a8c3051e5e165f4d511937be/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f62616b6f6d652f6c61726176656c2d76616c69646174696f6e2d61747472696275746573)](https://packagist.org/packages/bakome/laravel-validation-attributes)[![Tests](https://github.com/bakome/laravel-validation-attributes/workflows/Tests/badge.svg)](https://github.com/bakome/laravel-validation-attributes/workflows/Tests/badge.svg)[![Type Coverage](https://camo.githubusercontent.com/a77ae4c63791fec095f406053833633e5181fec0671d7ea992b626f33b864644/68747470733a2f2f73686570686572642e6465762f6769746875622f62616b6f6d652f6c61726176656c2d76616c69646174696f6e2d617474726962757465732f636f7665726167652e737667)](https://shepherd.dev/github/bakome/laravel-validation-attributes)

This package provides annotations to easily add validation rules on action methods in a controller. Here's a quick example:

```
use Bakome\ValidationAttributes\Attributes\ValidationRule;

class ExampleController
{
    #[ValidationRule('title', 'required|string')]
    public function actionMethod()
    {

    }
}
```

Motivation
----------

[](#motivation)

This project exists to provide simple and cleaner way to validate request data on Laravel controllers. Using validation rules in action methods often complicate readability of the controller and adding validation in separate requests classes imply switching trough that classes multiple time to view and change the rules (Losing focus). With this simple attributes we can make validation more accessible and maintainable in the controllers without messing the controller code.

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

[](#installation)

You can install the package via composer:

```
composer require bakome/laravel-validation-attributes
```

You can publish the config file with:

```
php artisan vendor:publish --provider="Bakome\ValidationAttributes\ValidationAttributesServiceProvider" --tag="config"
```

Usage
-----

[](#usage)

The package provides several annotations that should be put on controller action methods. These annotations are used to validate request data.

### Adding a validation rule with string as a parameter

[](#adding-a-validation-rule-with-string-as-a-parameter)

```
use Bakome\ValidationAttributes\Attributes\ValidationRule;

class ExampleController
{
    #[ValidationRule('title', 'required|string')]
    public function actionMethod()
    {

    }
}
```

This attribute will check if title parameter is present in current request and throw validation error if not present.

### Adding a validation rule with an array as a parameter

[](#adding-a-validation-rule-with-an-array-as-a-parameter)

```
use Bakome\ValidationAttributes\Attributes\ValidationRule;

class ExampleController
{
    #[ValidationRule('title', ['required', 'string'])]
    public function actionMethod()
    {

    }
}
```

This attribute will check if title parameter is present in current request and throw validation error if not present.

### Adding a multiple validation rules

[](#adding-a-multiple-validation-rules)

```
use Bakome\ValidationAttributes\Attributes\ValidationRule;

class ExampleController
{
    #[ValidationRule('description', 'required|string')]
    #[ValidationRule('title', ['required', 'string'])]
    public function actionMethod()
    {

    }
}
```

This attribute will check if title and description parameters are present in current request and throw validation error if not present.

### Adding a redirect for failed validation

[](#adding-a-redirect-for-failed-validation)

```
use Bakome\ValidationAttributes\Attributes\ValidationRule;
use Bakome\ValidationAttributes\Attributes\ValidationRuleRedirect;

class ExampleController
{
    #[ValidationRule('description', 'required|string')]
    #[ValidationRule('title', ['required', 'string'])]
    #[ValidationRuleRedirect('/a-redirection-route')]
    public function actionMethod()
    {

    }
}
```

This attribute will check if title and description parameters are present in current request, compile validation error messages and redirect the page to provided route.

### Adding a redirect with input for failed validation

[](#adding-a-redirect-with-input-for-failed-validation)

```
use Bakome\ValidationAttributes\Attributes\ValidationRule;
use Bakome\ValidationAttributes\Attributes\ValidationRuleRedirect;

class ExampleController
{
    #[ValidationRule('description', 'required|string')]
    #[ValidationRule('title', ['required', 'string'])]
    #[ValidationRuleRedirect('/a-redirection-route', true)]
    public function actionMethod()
    {

    }
}
```

This attribute will check if title and description parameters are present in current request, compile validation error messages and redirect the page to provided route including old input parameters.

### Ajax's requests awareness and proper json responses returned for failed validation

[](#ajaxs-requests-awareness-and-proper-json-responses-returned-for-failed-validation)

Config
------

[](#config)

### Plugin enabled/disabled

[](#plugin-enableddisabled)

```
'enabled' => true,

```

This plugin can be enabled or disabled with altering this property in configuration file. Default value is true (Enabled).

### Plugin enabled/disabled

[](#plugin-enableddisabled-1)

```
'middleware' => \Bakome\ValidationAttributes\Routing\Middleware\ValidationRulesByAttributes::class,

```

This property enables developers to provide a different handler for Validation via Middleware. Please be careful with this option and don't change it if you don't need custom behaviour.

### Validation middleware

[](#validation-middleware)

```
'middleware' => \Bakome\ValidationAttributes\Routing\Middleware\ValidationRulesByAttributes::class,

```

This property enables developers to provide a different handler for Validation via Middleware. Please be careful with this option and don't change it if you don't need custom behaviour.

### Detect api routes

[](#detect-api-routes)

```
'api_pattern' => 'api/*',

```

This property provide value for detecting api routes. Using expects json sometimes is not enough and when that lacks this option/feature do the job.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Roadmap
-------

[](#roadmap)

- Provide custom validation messages
- Provide validation groups to reduce boilerplate code

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

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

Total

2

Last Release

1953d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5086e005cbe774c5b9f6219bb25ae8a78500bb0a111c9b41a45a759e3df520b5?d=identicon)[bakome](/maintainers/bakome)

---

Tags

annotationsattributeslaravelvalidationattributeslaravel-validation-attributes

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/bakome-laravel-validation-attributes/health.svg)

```
[![Health](https://phpackages.com/badges/bakome-laravel-validation-attributes/health.svg)](https://phpackages.com/packages/bakome-laravel-validation-attributes)
```

###  Alternatives

[backpack/crud

Quickly build admin interfaces using Laravel, Bootstrap and JavaScript.

3.4k3.7M223](/packages/backpack-crud)[unopim/unopim

UnoPim Laravel PIM

10.5k2.4k](/packages/unopim-unopim)[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

135224.7k7](/packages/statamic-rad-pack-runway)[ecotone/laravel

Ecotone for Laravel — CQRS, Event Sourcing, Sagas, Durable Workflows, and Outbox on top of Laravel Queue, via PHP attributes.

21318.6k3](/packages/ecotone-laravel)[carsdotcom/laravel-json-schema

Json Schema validation for Laravel projects

1043.3k6](/packages/carsdotcom-laravel-json-schema)[duncanmcclean/statamic-cargo

Comprehensive e-commerce addon for Statamic. Build bespoke e-commerce sites without the complexity.

3416.6k](/packages/duncanmcclean-statamic-cargo)

PHPackages © 2026

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