PHPackages                             elvin-jatapp/nova-inline-relationship - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. elvin-jatapp/nova-inline-relationship

ActiveLibrary

elvin-jatapp/nova-inline-relationship
=====================================

A Laravel Nova field for displaying relationship properties inline.

05181PHP

Since Mar 30Pushed 3y agoCompare

[ Source](https://github.com/elvin-jatapp/nova-inline-relationship)[ Packagist](https://packagist.org/packages/elvin-jatapp/nova-inline-relationship)[ RSS](/packages/elvin-jatapp-nova-inline-relationship/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

[![Banner](https://raw.githubusercontent.com/kirschbaum-development/nova-inline-relationship/master/resources/imgs/banner.png "Banner")](https://raw.githubusercontent.com/kirschbaum-development/nova-inline-relationship/master/resources/imgs/banner.png)

Nova Inline Relationship
------------------------

[](#nova-inline-relationship)

[![Latest Version on Packagist](https://camo.githubusercontent.com/99d43da458ac7c501ac7574a85c3296c17fba6b603cf1c5f261fee5cd9a6eed3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b69727363686261756d2d646576656c6f706d656e742f6e6f76612d696e6c696e652d72656c6174696f6e736869702e737667)](https://packagist.org/packages/kirschbaum-development/nova-inline-relationship)[![Total Downloads](https://camo.githubusercontent.com/84d0505f97ea2b42187a8d4a727245322b14385f1e2b2fb3e615189763af1d24/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b69727363686261756d2d646576656c6f706d656e742f6e6f76612d696e6c696e652d72656c6174696f6e736869702e737667)](https://packagist.org/packages/kirschbaum-development/nova-inline-relationship)[![Actions Status](https://github.com/kirschbaum-development/nova-inline-relationship/workflows/CI/badge.svg)](https://github.com/kirschbaum-development/nova-inline-relationship/actions)

Nova Inline Relationship allows you to manage (add/edit/update/delete/reorder) an object's relationships directly from the parent object's create/edit screens. By presenting relationships as inline properties you can provide content editors with a streamlined and efficient workflow for managing complex data.

Requirements
------------

[](#requirements)

This package requires Laravel Nova 4.0.

Installation
------------

[](#installation)

You can install this package in a Laravel app that uses [Nova](https://nova.laravel.com) via composer:

```
composer require kirschbaum-development/nova-inline-relationship
```

Usage
-----

[](#usage)

To use `NovaInlineRelationship` in 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 field(s).

If we assume that a `BlogPost` model has a one-to-many relationship with `Image`, your `BlogPost` resource would look like the following:

```
namespace App\Nova;

use Laravel\Nova\Fields\Image;

class BlogPost extends Resource
{
    //...
    public function fields(Request $request)
    {
        return [
            //...

            HasMany::make('Images', 'images', Image::class)->inline(),
        ];
    }
}
```

***NOTE:*** You will need to add a Nova Resource for `Image` - all of the fields and rules will be retrieved from the specified resource. You must specify the resource as the third argument to the Relationship field as illustrated above.

Adding related models
---------------------

[](#adding-related-models)

[![Create View](screenshots/CreateView.png "Create View")](screenshots/CreateView.png)

After setup you can add new related models directly while creating a new base model. You can use the `Add new Image` button to add a new `Image` to the `BlogPost`:

[![Create Related Model](https://raw.githubusercontent.com/kirschbaum-development/nova-inline-relationship/master/screenshots/CreateViewExpanded.png "Create Related Model")](https://raw.githubusercontent.com/kirschbaum-development/nova-inline-relationship/master/screenshots/CreateViewExpanded.png)

Viewing related models
----------------------

[](#viewing-related-models)

Related models will also now be displayed inline as well:

[![Detail View](https://raw.githubusercontent.com/kirschbaum-development/nova-inline-relationship/master/screenshots/DetailView.png "Detail View")](https://raw.githubusercontent.com/kirschbaum-development/nova-inline-relationship/master/screenshots/DetailView.png)

Updating related models
-----------------------

[](#updating-related-models)

You can also update, re-arrange (for one-to-many relationships), and delete related models:

[![Rearrange Models](https://raw.githubusercontent.com/kirschbaum-development/nova-inline-relationship/master/screenshots/UpdateView.png "Rearrange Models")](https://raw.githubusercontent.com/kirschbaum-development/nova-inline-relationship/master/screenshots/UpdateView.png)

You can add drag and drop functionality for related models to update their order by using the `sortUsing()` method. In the following code example we use a field named `order` to store the sort order for the `Images` model:

```
HasMany::make('Images')->inline()->sortUsing('order'),
```

Required Relationships
----------------------

[](#required-relationships)

Occasionally you may want to require a child relationship during the creation of a model. To do this, just use the `requireChild()` method. As an example, you may want to create a new user and enforce that a new profile for the user is also created.

```
HasOne::make('Profile', 'profile', Profile::class)->inline()->requireChild(),
```

Support for Third Party Packages
--------------------------------

[](#support-for-third-party-packages)

We have included a simple way to address some issues regarding third party packages occasionally not working with Nova Inline Relationships. These packages occasionally handle how they return their subset of fields slightly different. We have a way of easily integrating functionality for these packages. This may not work across the board, but should allow for most third party packages.

You must publish the configs for this package with

```
php artisan vendor:publish
```

This will publish a config file as `config/nova-inline-relationships.php`. Add your custom namespaced paths within the `third-party` array. For example:

```
'third-party' => [
    'App\Nova\ThirdPartyIntegrations',
    'KirschbaumDevelopment\NovaInlineRelationship\Integrations',
]
```

Create a new class inside that namespace that looks like the following:

```
