This field works just like as the default HasMany relationship field from nova but without requiring a real relation with the resource.
That means you are free to show resource A
into the details page of resource B
without they having a real bound though the standard relationship in laravel.
You can install the package via composer:
composer require digital-creative/custom-relationship-field
Next add the CustomRelationshipField
to the resource you wanna display the relation.
use DigitalCreative\CustomRelationshipField\CustomRelationshipField;
use DigitalCreative\CustomRelationshipField\CustomRelationshipFieldTrait;
class Client extends Resource
{
use CustomRelationshipFieldTrait;
public function fields()
{
return [
Text::make('Name')->rules('required'),
// ...
CustomRelationshipField::make('Clients with similar name', 'similarName', self::class),
];
}
public function similarNameFields(): array
{
return [
ID::make()->sortable(),
Text::make('Name'),
Text::make('Age'),
//...
];
}
public static function similarNameQuery(NovaRequest $request, $query, Model $model)
{
return $query->where('name', 'SOUNDS LIKE', $model->name)->whereKeyNot($model->getKey());
}
}
The MIT License (MIT). Please see License File for more information.