Open Dontorpedo opened 3 years ago
Apologies for bringing back a stale issue, but wanted to share this in case anyone else is looking for this feature.
You can accomplish this out-of-the-box via some creative Nova use:
Create a Nova resource to represent your Nova Notes, just like any other Nova resource. The more important part is setting the $search
property to the fields you want to be able to search globally (probably the 'text'
field). Once this resource is in place and registered with Nova, you will find it on the navigation sidebar (where you can view and perform a resource-specific search/filtering) and the notes will be globally searchable.
Hope this helps.
Here's some inspiration:
<?php
namespace App\Nova;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\Boolean;
use Laravel\Nova\Fields\DateTime;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\MorphTo;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\Trix;
use Laravel\Nova\Http\Requests\NovaRequest;
class NovaNote extends Resource
{
public static $model = \Outl1ne\NovaNotesField\Models\Note::class;
public static $search = [
'text',
];
public function subtitle(): ?string
{
return $this->text;
}
public function fields(NovaRequest $request): array
{
return [
ID::make()->sortable(),
MorphTo::make('Notable')
->types([
User::class,
])
->searchable(),
BelongsTo::make('Created By', 'createdBy', User::class)
->searchable(),
// This Text field is optional and is present so we can see the note on the Index page.
Text::make('Text')
->onlyOnIndex()
->asHtml(),
// Could also use a Textarea field if you normally use that to write Nova notes.
Trix::make('Text')
->alwaysShow()
->hideFromIndex(),
Boolean::make('System')->readonly(),
DateTime::make('Created At')->readonly(),
DateTime::make('Updated At')->readonly(),
];
}
// ...
// Add any custom authorization, actions, filters, etc.
}
Hello,
is it possible to make te notes searchable trough the resource search?
thanks