<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
digital-creative / custom-relationship-field example snippets
use DigitalCreative\CustomRelationshipField\CustomRelationshipField;
use DigitalCreative\CustomRelationshipField\CustomRelationshipFieldTrait;
trait UserWithSimilarNameTrait
{
public static function similarNameQuery(NovaRequest $request, Builder $query, User $model): Builder
{
return $query->where('last_name', $model->last_name)->whereKeyNot($model->getKey());
}
public function similarNameFields(NovaRequest $request): array
{
return [
ID::make(),
Text::make('First Name'),
Text::make('Last Name'),
];
}
public function similarNameActions(NovaRequest $request): array
{
return [];
}
public function similarNameFilters(NovaRequest $request): array
{
return [];
}
}
class User extends Resource
{
use CustomRelationshipFieldTrait;
use UserWithSimilarNameTrait;
public function fields(NovaRequest $request): array
{
return [
...
CustomRelationshipField::make('Users with similar name', 'similarName', User::class),
...
];
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.