Skip to content

Commit e9cca4a

Browse files
authored
Merge pull request #26 from dreammonkey/main
Add support for Laravel 11
2 parents 9f495a8 + 2844553 commit e9cca4a

File tree

6 files changed

+56
-31
lines changed

6 files changed

+56
-31
lines changed

Diff for: .github/workflows/run-tests.yml

+10-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ jobs:
1414
matrix:
1515
os: [ubuntu-latest]
1616
php: [8.3, 8.2, 8.1, 8.0, 7.4]
17-
laravel: [10.*, 9.*, 8.*]
17+
laravel: [11.*, 10.*, 9.*, 8.*]
1818
stability: [prefer-lowest, prefer-stable]
1919
include:
20+
- laravel: 11.*
21+
testbench: 9.*
22+
carbon: ^2.63
2023
- laravel: 10.*
2124
testbench: 8.*
2225
carbon: ^2.63
@@ -27,6 +30,12 @@ jobs:
2730
testbench: 6.27
2831
carbon: ^2.63
2932
exclude:
33+
- laravel: 11.*
34+
php: 8.1
35+
- laravel: 11.*
36+
php: 8.0
37+
- laravel: 11.*
38+
php: 7.4
3039
- laravel: 10.*
3140
php: 8.0
3241
- laravel: 10.*

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ phpstan.neon
99
testbench.yaml
1010
vendor
1111
node_modules
12+
.phpunit.cache

Diff for: README.md

+31-16
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[![Total Downloads](https://img.shields.io/packagist/dt/laracraft-tech/laravel-schema-rules.svg?style=flat-square)](https://packagist.org/packages/laracraft-tech/laravel-schema-rules)
88

99
Automatically generate basic Laravel validation rules based on your database table schema!
10-
Use these as a starting point to fine-tune and optimize your validation rules as needed.
10+
Use these as a starting point to fine-tune and optimize your validation rules as needed.
1111

1212
Here you can use the web version, if you like: [https://validationforlaravel.com](https://validationforlaravel.com)
1313

@@ -27,15 +27,27 @@ php artisan vendor:publish --tag="schema-rules-config"
2727

2828
## ToC
2929

30-
- [`Generate rules for a whole table`](#generate-rules-for-a-whole-table)
31-
- [`Generate rules for specific columns`](#generate-rules-for-specific-columns)
32-
- [`Generate Form Request Class`](#generate-form-request-class)
30+
- [Laravel Schema Rules](#laravel-schema-rules)
31+
- [Installation](#installation)
32+
- [ToC](#toc)
33+
- [Usage](#usage)
34+
- [Generate rules for a whole table](#generate-rules-for-a-whole-table)
35+
- [Generate rules for specific columns](#generate-rules-for-specific-columns)
36+
- [Generate Form Request Class](#generate-form-request-class)
37+
- [Always skip columns](#always-skip-columns)
38+
- [Supported Drivers](#supported-drivers)
39+
- [Testing](#testing)
40+
- [Changelog](#changelog)
41+
- [Contributing](#contributing)
42+
- [Security Vulnerabilities](#security-vulnerabilities)
43+
- [Credits](#credits)
44+
- [License](#license)
3345

3446
## Usage
3547

3648
Let's say you've migrated this fictional table:
3749

38-
````php
50+
```php
3951
Schema::create('persons', function (Blueprint $table) {
4052
$table->id();
4153
$table->string('first_name', 100);
@@ -52,7 +64,7 @@ Schema::create('persons', function (Blueprint $table) {
5264
$table->unsignedInteger('net_income');
5365
$table->boolean('send_newsletter')->nullable();
5466
});
55-
````
67+
```
5668

5769
### Generate rules for a whole table
5870

@@ -61,6 +73,7 @@ Now if you run:
6173
`php artisan schema:generate-rules persons`
6274

6375
You'll get:
76+
6477
```
6578
Schema-based validation rules for table "persons" have been generated!
6679
Copy & paste these to your controller validation or form request or where ever your validation takes place:
@@ -82,7 +95,7 @@ Copy & paste these to your controller validation or form request or where ever y
8295
```
8396

8497
As you may have noticed the float-column `body_size`, just gets generated to `['required', 'numeric']`.
85-
Proper rules for `float`, `decimal` and `double`, are not yet implemented!
98+
Proper rules for `float`, `decimal` and `double`, are not yet implemented!
8699

87100
### Generate rules for specific columns
88101

@@ -91,28 +104,29 @@ You can also explicitly specify the columns:
91104
`php artisan schema:generate-rules persons --columns first_name,last_name,email`
92105

93106
Which gives you:
94-
````
107+
108+
```
95109
Schema-based validation rules for table "persons" have been generated!
96110
Copy & paste these to your controller validation or form request or where ever your validation takes place:
97111
[
98112
'first_name' => ['required', 'string', 'min:1', 'max:100'],
99113
'last_name' => ['required', 'string', 'min:1', 'max:100'],
100114
'email' => ['required', 'string', 'min:1', 'max:255']
101115
]
102-
````
116+
```
103117

104118
### Generate Form Request Class
105119

106120
Optionally, you can add a `--create-request` or `-c` flag,
107121
which will create a form request class with the generated rules for you!
108122

109-
```` bash
123+
```bash
110124
# creates app/Http/Requests/StorePersonRequest.php (store request is the default)
111-
php artisan schema:generate-rules persons --create-request
125+
php artisan schema:generate-rules persons --create-request
112126

113127
# creates/overwrites app/Http/Requests/StorePersonRequest.php
114128
php artisan schema:generate-rules persons --create-request --force
115-
129+
116130
# creates app/Http/Requests/UpdatePersonRequest.php
117131
php artisan schema:generate-rules persons --create-request --file UpdatePersonRequest
118132

@@ -121,7 +135,7 @@ php artisan schema:generate-rules persons --create-request --file Api\\V1\\Store
121135

122136
# creates/overwrites app/Http/Requests/Api/V1/StorePersonRequest.php (using shortcuts)
123137
php artisan schema:generate-rules persons -cf --file Api\\V1\\StorePersonRequest
124-
````
138+
```
125139

126140
### Always skip columns
127141

@@ -131,7 +145,6 @@ To always skip columns add it in the config file, under `skip_columns` parameter
131145
'skip_columns' => ['whatever', 'some_other_column'],
132146
```
133147

134-
135148
## Supported Drivers
136149

137150
Currently, the supported database drivers are `MySQL`, `PostgreSQL`, and `SQLite`.
@@ -141,6 +154,8 @@ the validation rules generated by this package may vary depending on the databas
141154

142155
## Testing
143156

157+
Before running tests, you need to set up a local MySQL database named `laravel_schema_rules` and update its _username_ and _password_ in the `phpunit.xml.dist` file.
158+
144159
```bash
145160
composer test
146161
```
@@ -159,8 +174,8 @@ Please review [our security policy](../../security/policy) on how to report secu
159174

160175
## Credits
161176

162-
- [Zacharias Creutznacher](https://github.com/laracraft-tech)
163-
- [All Contributors](../../contributors)
177+
- [Zacharias Creutznacher](https://github.com/laracraft-tech)
178+
- [All Contributors](../../contributors)
164179

165180
## License
166181

Diff for: composer.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@
1616
}
1717
],
1818
"require": {
19-
"php": "^7.4 || ^8.0",
20-
"brick/varexporter": "^0.3.8",
21-
"doctrine/dbal": "^3.6 || ^4.0",
22-
"illuminate/contracts": "^8.0 || ^9.0 || ^10.0",
23-
"illuminate/database": "^8.0 || ^9.0 || ^10.0",
24-
"illuminate/support": "^8.0 || ^9.0 || ^10.0",
25-
"illuminate/testing": "^8.0 || ^9.0 || ^10.0",
19+
"php": "^7.4 || ^8.0 || ^8.1",
20+
"brick/varexporter": "^0.3.8 || ^0.5.0",
21+
"doctrine/dbal": "^3.6 || ^4.0.2",
22+
"illuminate/contracts": "^8.0 || ^9.0 || ^10.0 || ^11.0",
23+
"illuminate/database": "^8.0 || ^9.0 || ^10.0 || ^11.0",
24+
"illuminate/support": "^8.0 || ^9.0 || ^10.0 || ^11.0",
25+
"illuminate/testing": "^8.0 || ^9.0 || ^10.0 || ^11.0",
2626
"spatie/laravel-package-tools": "^1.12 || ^1.14"
2727
},
2828
"require-dev": {
2929
"friendsofphp/php-cs-fixer": "^3.13",
3030
"nunomaduro/larastan": "^1.0 || ^2.5",
31-
"orchestra/testbench": "^6.27 || ^7.0 || ^8.0 ",
31+
"orchestra/testbench": "^6.27 || ^7.0 || ^8.0 || ^9.0 ",
3232
"pestphp/pest": "^1.22 || ^2.0",
3333
"pestphp/pest-plugin-laravel": "^1.22 || ^2.0",
3434
"spatie/laravel-ray": "^1.32"
@@ -64,4 +64,4 @@
6464
},
6565
"minimum-stability": "dev",
6666
"prefer-stable": true
67-
}
67+
}

Diff for: config/schema-rules.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
return [
44
/**
5-
* In MySQL for instance there is no nativ boolean data type.
5+
* In MySQL for instance there is no native boolean data type.
66
* Laravel creates a tinyint(1) if you migrate a boolean.
77
* Switch this off if you want an actual tinyint
88
* validation rule to be generated...
@@ -16,7 +16,7 @@
1616
'string_min_length' => env('SCHEMA_RULES_STRING_MIN_LENGTH', 1),
1717

1818
/**
19-
* Always skip this columns
19+
* Always skip these columns
2020
*/
2121
'skip_columns' => ['created_at', 'updated_at', 'deleted_at'],
2222

Diff for: tests/SchemaRulesTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,11 @@
258258
$decimalNullableColumnName
259259
) {
260260
$table->float($floatColumnName);
261-
$table->unsignedFloat($floatUnsignedColumnName);
261+
$table->float($floatUnsignedColumnName)->unsigned();
262262
$table->double($doubleColumnName);
263-
$table->unsignedDouble($doubleUnsignedColumnName);
263+
$table->double($doubleUnsignedColumnName)->unsigned();
264264
$table->decimal($decimalColumnName);
265-
$table->unsignedDecimal($decimalUnsignedColumnName);
265+
$table->decimal($decimalUnsignedColumnName)->unsigned();
266266
$table->decimal($decimalNullableColumnName)->nullable();
267267
});
268268

0 commit comments

Comments
 (0)