Download the PHP package pi-space/laravel-typed-request without Composer
On this page you can find all versions of the php package pi-space/laravel-typed-request. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pi-space/laravel-typed-request
More information about pi-space/laravel-typed-request
Files in pi-space/laravel-typed-request
Package laravel-typed-request
Short Description This is my package laravel-typed-request
License MIT
Homepage https://github.com/pi-space/laravel-typed-request
Informations about the package laravel-typed-request
Laravel Typed Request
Laravel Typed Request is a package that enhances Laravel Form Request by introducing Typed Classes and Attribute-based Validation Rules.
This package provides a seamless way to create type-safe request classes, resulting in improved code readability and enhanced IDE support.
Features
- Define Typed Form Request classes with attribute-based validation rules.
- Improved code readability and maintainability.
- Enhanced IDE support for auto-completion and error checking.
Installation
You can install the package via composer:
Usage
Creating Typed Form Request Classes
Laravel Typed Request simplifies the process of creating Typed Form Request classes. Let's take an example of creating an ArticleRequest
class:
-
To create a typed request class, use the following Artisan command:
- Open the generated
app/Http/Requests/ArticleRequest.php
file and update it as follows:
Important Notes
- The typed request class must extend the
PiSpace\LaravelTypedRequest\TypedFormRequest
class. - All properties in the typed request class must be
readonly
.
Available Rules
- All available rules are located in the
PiSpace\LaravelTypedRequest\Rules
namespace. These rules are attribute-based and are similar to Laravel validation rules. - You can create custom rules by extending the
PiSpace\LaravelTypedRequest\Rules\RuleAttribute
class. - For example, the
RequiredIfPatch
rule checks if the request method isPATCH
, making the attribute required only in that case. - You have access to the request instance inside custom rule classes, allowing you to access request data.
Creating a Custom Rule
Let's create a custom rule called RequiredIfPatch
:
-
To create the custom rule class, use the following Artisan command:
- Open the generated
app/Rules/RequiredIfPatch.php
file and update it as follows:
Now you can use the RequiredIfPatch
rule in your typed request classes.
Changelog
For a detailed list of changes, see the CHANGELOG.
Contributing
We welcome contributions! Please see CONTRIBUTING for details on how to get involved.
Security Vulnerabilities
If you discover any security vulnerabilities, please review our security policy on how to report them.
Credits
- Eyad Hamza
- All Contributors
License
The MIT License (MIT). See License File for more information.
All versions of laravel-typed-request with dependencies
spatie/laravel-package-tools Version ^1.14.0
illuminate/contracts Version ^10.0