Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

searchable notes #31

Open
Dontorpedo opened this issue Mar 9, 2021 · 1 comment
Open

searchable notes #31

Dontorpedo opened this issue Mar 9, 2021 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@Dontorpedo
Copy link

Hello,

is it possible to make te notes searchable trough the resource search?

thanks

@steven-fox
Copy link
Contributor

steven-fox commented Apr 20, 2023

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.

}

@richard-raadi richard-raadi added enhancement New feature or request help wanted Extra attention is needed labels Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants