Skip to content

Commit 0c9c600

Browse files
authored
fixed form validation for nested DependencyContainer fields (#4)
nested DependencyContainer fields are now correctly validated
1 parent 9c16f38 commit 0c9c600

File tree

2 files changed

+90
-72
lines changed

2 files changed

+90
-72
lines changed

readme.md

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,27 @@
11
# nova 4 dependency container
22

3-
This plugin based on [epartment/nova-dependency-container](https://github.com/epartment/nova-dependency-container) and
4-
only supports Nova 4 and php 8.
5-
6-
### Description
7-
83
A Laravel Nova 4 form container for grouping fields that depend on other field values. Dependencies can be set on any
94
field type or value.
105

11-
### Demo
12-
13-
![Demo](https://raw.githubusercontent.com/alexwenzel/nova-dependency-container/master/docs/demo.gif)
6+
This plugin is based on [epartment/nova-dependency-container](https://github.com/epartment/nova-dependency-container)
7+
and only supports **Nova 4.x** and **PHP 8.x**.
148

15-
### Versions
9+
## Demo
1610

17-
This Nova plugin only works with **Nova 4.x** and **PHP 8.x**
11+
![Demo](https://raw.githubusercontent.com/alexwenzel/nova-dependency-container/master/docs/demo.gif)
1812

19-
### Installation
13+
## Installation
2014

2115
The package can be installed through Composer.
2216

2317
```bash
2418
composer require alexwenzel/nova-dependency-container
2519
```
2620

27-
### Usage
21+
## Usage
2822

2923
1. Add the `Alexwenzel\DependencyContainer\HasDependencies` trait to your Nova Resource.
30-
2. Add the `Alexwenzel\DependencyContainer\DependencyContainer` to your Nova Resource `fields` method.
24+
2. Add the `Alexwenzel\DependencyContainer\DependencyContainer` to your Nova Resource `fields()` method.
3125
3. Add the `Alexwenzel\DependencyContainer\ActionHasDependencies` trait to your Nova Actions that you wish to use
3226
dependencies on.
3327

@@ -39,7 +33,6 @@ class Page extends Resource
3933
public function fields(Request $request)
4034
{
4135
return [
42-
4336
Select::make('Name format', 'name_format')->options([
4437
0 => 'First Name',
4538
1 => 'First Name / Last Name',
@@ -49,15 +42,14 @@ class Page extends Resource
4942
DependencyContainer::make([
5043
Text::make('First Name', 'first_name')
5144
])->dependsOn('name_format', 0),
52-
5345
];
5446
}
5547
}
5648
```
5749

58-
### Dependencies
50+
## Available dependencies
5951

60-
The package supports this kinds of dependencies:
52+
The package supports these kinds of dependencies:
6153

6254
1. `->dependsOn('field', 'value')`
6355
2. `->dependsOnNot('field', 'value')`
@@ -67,7 +59,7 @@ The package supports this kinds of dependencies:
6759
6. `->dependsOnIn('field', [array])`
6860
7. `->dependsOnNotIn('field', [array])`
6961

70-
These dependencies can be combined by chaining the methods on the `DependencyContainer`:
62+
These dependencies can be combined by chaining the methods on the `DependencyContainer` field:
7163

7264
```php
7365
DependencyContainer::make([
@@ -85,7 +77,7 @@ Here is an example using a checkbox:
8577

8678
![Demo](https://raw.githubusercontent.com/alexwenzel/nova-dependency-container/master/docs/demo-2.gif)
8779

88-
### BelongsTo dependency
80+
## BelongsTo dependency
8981

9082
If we follow the example of a *Post model belongsTo a User model*, taken from Novas
9183
documentation [BelongsTo](https://nova.laravel.com/docs/2.0/resources/relationships.html#belongsto), the dependency
@@ -106,7 +98,7 @@ DependencyContainer::make([
10698

10799
When the `Post` resource with `id` 2 is being selected, a `Boolean` field will appear.
108100

109-
### BelongsToMany dependency
101+
## BelongsToMany dependency
110102

111103
A [BelongsToMany](https://nova.laravel.com/docs/2.0/resources/relationships.html#belongstomany) setup is similar to that
112104
of a [BelongsTo](https://nova.laravel.com/docs/2.0/resources/relationships.html#belongsto).
@@ -141,20 +133,16 @@ Here is an (ugly) example of a get/set mutator setup for an intermediate table u
141133
```php
142134
// model User
143135
class User ... {
144-
145-
public function roles() {
146-
return $this->belongsToMany->using(RoleUser::class)->withPivot('rules_all');
147-
}
148-
136+
public function roles() {
137+
return $this->belongsToMany->using(RoleUser::class)->withPivot('rules_all');
138+
}
149139
}
150140

151141
// model Role
152142
class Role ... {
153-
154-
public function users() {
155-
return $this->belongsToMany->using(RoleUser::class)->withPivot('rules_all');
156-
}
157-
143+
public function users() {
144+
return $this->belongsToMany->using(RoleUser::class)->withPivot('rules_all');
145+
}
158146
}
159147

160148
// intermediate table
@@ -188,8 +176,7 @@ And now for the dependency container.
188176
])
189177
->displayUsingLabels()
190178
])
191-
->dependsOn('role_user', 1)
192-
,
179+
->dependsOn('role_user', 1),
193180

194181
DependencyContainer::make([
195182
// pivot field rules_all
@@ -199,15 +186,14 @@ And now for the dependency container.
199186
])
200187
->displayUsingLabels()
201188
])
202-
->dependsOn('role_user', 2)
203-
,
189+
->dependsOn('role_user', 2),
204190

205191
// .. and so on
206192
]
207193
}),
208194
```
209195

210-
### MorphTo dependency
196+
## MorphTo dependency
211197

212198
A similar example taken from Novas documentation
213199
for [MorphTo](https://nova.laravel.com/docs/2.0/resources/relationships.html#morphto) is called commentable. It uses 3
@@ -232,7 +218,7 @@ DependencyContainer::make([
232218
->dependsOn('commentable', 'Post')
233219
```
234220

235-
### License
221+
## License
236222

237223
The MIT License (MIT). Please
238224
see [License File](https://github.com/alexwenzel/nova-dependency-container/blob/master/LICENSE.md) for more information.

0 commit comments

Comments
 (0)