You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After installation, your model should include the `KirschbaumDevelopment\NovaInlineRelationship\Traits\HasRelatedAttributes` trait and you must implement the `KirschbaumDevelopment\NovaInlineRelationship\Contracts\MappableRelationships` Contract.
23
-
24
-
You must also define a static `getPropertyMap` function in the model which should return the required list of properties from your related models you want to show inline.
25
-
In this example `Employee` model has two related models `EmployeeProfile` and `EmployeeBill`
26
-
27
-
```php
28
-
use KirschbaumDevelopment\NovaInlineRelationship\Traits\HasRelatedAttributes;
29
-
use KirschbaumDevelopment\NovaInlineRelationship\Contracts\MappableRelationships;
30
-
31
-
class Employee extends Model implements MappableRelationships
32
-
{
33
-
use HasRelatedAttributes;
34
-
35
-
/**
36
-
* @return HasOne
37
-
*/
38
-
public function profile(): HasOne
39
-
{
40
-
return $this->hasOne(EmployeeProfile::class);
41
-
}
42
-
43
-
/**
44
-
* @return HasMany
45
-
*/
46
-
public function bills(): HasMany
47
-
{
48
-
return $this->hasMany(EmployeeBill::class);
49
-
}
50
-
51
-
52
-
/**
53
-
* Should return property map as key value pair.
54
-
*
55
-
* @return array
56
-
*/
57
-
public static function getPropertyMap(): array
58
-
{
59
-
return [
60
-
'profile' => [
61
-
'nickname' => [
62
-
'label' => 'nickname',
63
-
'component' => \Laravel\Nova\Fields\Text::class,
64
-
'rules' => 'required',
65
-
'placeholder' => 'Add Nickname',
66
-
'messages' => ['required' => 'You must add a :attribute for this profile.'],
Once you add this relationship map you can add `NovaInlineRelationship` to your Model's resource with a relationship.
22
+
To use `NovaInlineRelationship` to your Model's resource all you need to do is to add an inline method to the regular syntax of your related Model's Resource.
126
23
24
+
If we assume that an Employee Models has a one-to-one relationship with `EmployeeProfile` and one-to-many relationship with `EmployeeBill` model then the code will look like:
25
+
127
26
```php
128
27
namespace App\Nova;
129
28
@@ -136,14 +35,14 @@ class Employee extends Resource
**_NOTE:_**These fields are in essence [Computed Fields](https://nova.laravel.com/docs/2.0/resources/fields.html#computed-fields), and are subjected to the same limitations. Since they are not associated with a database column, these fields will not be `sortable`.
45
+
**_NOTE:_**You will need to add NovaResources for `EmployeeProfile` and `EmployeeBill` Model and all the field and rules will be fetch from it.
147
46
148
47
## Adding related models
149
48
@@ -177,65 +76,6 @@ For `one-to-many` relationships you can drag and drop related models to rearrang
177
76
178
77
You can delete related models from the base model's update view by using the `delete button` at the top right corner.
179
78
180
-
## Validating related models
181
-
182
-
You can specify the validation rule for the fields in your related model using the `getPropertyMap()` function.
183
-
184
-
An error will be displayed next to field if a validation rule is not met.
You can specify custom error messages for field in format specified in the [laravel documentation](https://laravel.com/docs/5.8/validation#customizing-the-error-messages).
191
-
192
-
For every field you can specify validation messages for each rule. You can use attribute wildcards like `:attribute` in your error messages as well.
193
-
194
-
```php
195
-
use KirschbaumDevelopment\NovaInlineRelationship\Traits\HasRelatedAttributes;
196
-
use KirschbaumDevelopment\NovaInlineRelationship\Contracts\MappableRelationships;
197
-
198
-
class Employee extends Model implements MappableRelationships
199
-
{
200
-
// ...
201
-
202
-
/**
203
-
* Should return property map as key value pair.
204
-
*
205
-
* @return array
206
-
*/
207
-
public static function getPropertyMap(): array
208
-
{
209
-
return [
210
-
'profile' => [
211
-
'phone' => [
212
-
'component => Number::class,
213
-
'label' => 'Phone',
214
-
'rules' => 'required|numeric',
215
-
'placeholder' => 'Add Phone',
216
-
'messages' => [
217
-
'required' => 'You must add a :attribute for this profile.',
218
-
'numeric' => 'Your :attribute must be numeric'
219
-
],
220
-
],
221
-
],
222
-
];
223
-
}
224
-
225
-
// ...
226
-
}
227
-
```
228
-
229
-
## Settings
230
-
231
-
You can pass on following items for your related model's attributes:-
232
-
1.`component`: The component use to render the field. You should provide the component name specified in the field like Text::class, Number::class, Boolean::class and so on.
233
-
2.`label`: Label for your field. This will also be used as the field name in error messages.
234
-
3.`rules`: A rule string in [Laravel Validation format](https://laravel.com/docs/5.8/validation#available-validation-rules).
235
-
4.`messages`: An array of error messages to be used in validation.
236
-
5.`placeholder`: A placeholder for your field.
237
-
6.`options`: Additional options for your components
238
-
239
79
## Supported fields
240
80
241
81
You can use any field you can add to your Nova resource with `Field::make` syntax. The following native Nova 2.0 fields are confirmed to work.
@@ -259,29 +99,6 @@ You can use any field you can add to your Nova resource with `Field::make` synta
259
99
- Image Field
260
100
- File Field
261
101
262
-
### Select Component
263
-
To pass dropdown options to your select component, pass an array of key values to options
264
-
```php
265
-
'component => Select::class,
266
-
'options' => [
267
-
'options' => [
268
-
['label' => 'Yes', 'value' => true],
269
-
['label' => 'No', 'value' => false],
270
-
],
271
-
]
272
-
```
273
-
274
-
### Number/Currency Component
275
-
You can pass `min`, `max` and `step` to number and currency field
276
-
```php
277
-
'component' => Currency::class,
278
-
'options' => [
279
-
'min' => 0,
280
-
'max' => 100,
281
-
'step' => 10,
282
-
],
283
-
```
284
-
285
102
## Changelog
286
103
287
104
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
@@ -292,7 +109,7 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
292
109
293
110
## Security
294
111
295
-
If you discover any security related issues, please email brandon@kirschbaumdevelopment.com or nathan@kirschbaumdevelopment.com instead of using the issue tracker.
112
+
If you discover any security related issues, please email navneet@kirschbaumdevelopment.com or nathan@kirschbaumdevelopment.com instead of using the issue tracker.
0 commit comments