├── LICENSE
├── README.md
├── composer.json
├── pint.json
└── src
├── PreflightMiddleware.php
└── PreflightServiceProvider.php
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 Boris Lepikhin.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Momentum Preflight
2 |
3 | Momentum Preflight is a Laravel package that lets you implement realtime backend-driven request validation for Inertia apps.
4 |
5 | Validate form requests using Inertia form helper just like you already do, without running controllers' code.
6 |
7 | - [**Advanced Inertia**](#advanced-inertia)
8 | - [**Installation**](#installation)
9 | - [**Laravel**](#laravel)
10 | - [**Vue 3**](#vue-3)
11 | - [**Usage**](#usage)
12 | - [**Momentum**](#momentum)
13 |
14 | ## Installation
15 |
16 | ### Laravel
17 |
18 | Install the package into your Laravel app.
19 |
20 | ```bash
21 | composer require based/momentum-preflight
22 | ```
23 |
24 | Register the `PreflightMiddleware` middleware.
25 |
26 | ```php
27 | middleware(PreflightMiddleware::class);
31 | ```
32 |
33 | ### Vue 3
34 |
35 | > The frontend package is only for Vue 3 now due to its wide adoption within the Laravel community.
36 |
37 | Install the [frontend package](https://github.com/lepikhinb/momentum-preflight-plugin).
38 |
39 | ```bash
40 | npm i momentum-preflight
41 | # or
42 | yarn add momentum-preflight
43 | ```
44 |
45 | ## Usage
46 |
47 | Preflight works well with both [FormRequests](https://laravel.com/docs/9.x/validation#form-request-validation) and [Laravel Data](https://spatie.be/docs/laravel-data/v2/as-a-data-transfer-object/request-to-data-object). Due to the simplicity of the approach, it doesn't support the inline `$request->validate(...)` method.
48 |
49 | ```php
50 | form.data(),
71 | () => validate()
72 | );
73 | ```
74 |
75 | The package performs validation for all defined rules. However, you can specify exact fields so that all errors don't appear together once you start typing.
76 |
77 | ```vue
78 |
86 |
87 |
88 |