Skip to content

Commit a201e69

Browse files
authored
Updated Readme
* Updated Readme
1 parent 18d2781 commit a201e69

1 file changed

Lines changed: 62 additions & 7 deletions

File tree

README.md

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# Nova Inline Relationship
22

33
## Introduction
4-
Nova Inline Relationship is meant to present a relationship based property as an inline property for a Laravel Nova Resource.
4+
Nova Inline Relationship is meant to present a relationship based property as an inline property for a Laravel Nova Resource. This project is under active development, and currently only supports singular relationships. You are welcome to request or contribute by opening an issue.
55

6-
**This is a pre-release project in Active Development. Frequent Changes are expected**
76

87
## Requirements
98

@@ -17,14 +16,70 @@ You can install this package in a Laravel app that uses [Nova](https://nova.lara
1716
composer require kirschbaum-development/nova-inline-relationship
1817
```
1918

19+
## Setup
20+
21+
After installation, your model should include the `KirschbaumDevelopment\NovaInlineRelationship\Traits\HasRelatedAttributes` trait and you must implement the `KirschbaumDevelopment\NovaInlineRelationship\Contracts\MappableRelationships` Contract.
22+
23+
You must also define a static `getPropertyMap` function in the model which should return the required mapping between local and related attribute.
24+
25+
**_NOTE:_** You must add relationships in `relationship.attribute` format in the map. Nested relationships are currently not supported.
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+
* Should return property map as key value pair.
45+
*
46+
* @return array
47+
*/
48+
public static function getPropertyMap(): array
49+
{
50+
return ['phone' => 'profile.phone', 'fax' => 'profile.fax'];
51+
}
52+
53+
// ...
54+
}
55+
````
56+
2057
## Usage
2158

22-
Coming Soon
59+
Once you add this relationship map you can use the keys for this relationship map as a normal attribute inside your model's nova resource.
60+
61+
**_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`.
62+
63+
```php
64+
namespace App\Nova;
65+
66+
class Employee extends Resource
67+
{
68+
69+
//...
70+
public function fields(Request $request)
71+
{
72+
return [
73+
//...
74+
75+
Text::make('Phone #', 'phone')
76+
->rules('required'),
2377

24-
## To-Do
25-
- [x] Setup Repo
26-
- [ ] Present a Relationship property as inline using computed field
27-
- [ ] Update a Relationship property by overloading mutator magic method
78+
Number::make('Fax Number', 'fax'),
79+
];
80+
}
81+
}
82+
```
2883

2984
## Changelog
3085

0 commit comments

Comments
 (0)