Home > Enterprise >  hot to display name instead of id in laravel Nova
hot to display name instead of id in laravel Nova

Time:10-14

We want to stop algolia from nova dashboard only but we want to add algolia to website and api, when we add Laravel\Scout\Searchable to user model it work for both nova dashboard and website & API

Another question: i want to show name here instead of id but didn't work, what can i do ?

BelongsTo::make('Student', 'student', StudentDetail::class)
                ->nullable()
                ->sortable()
                ->searchable(),

CodePudding user response:

looking at the Laravel\Nova\Resource class, I found that the usesScout method determines whether or not Scout should be used for search. So in my Nova resources, I simply override this method:

public static function usesScout()
{
    return false;
}

CodePudding user response:

As per the other answer, if you want to disable scout try:

public static function usesScout()
{
    return false;
}

To display something other than the ID to identify a Nova resource you can

  1. This is the simplest solution. Assign the "$title" property with the name of the eloquent property you want to use.

For example this would show the 'ID' as the title for your resource:

public static $title = 'id';

Whereas this would show the 'Name' as the title:

namespace App\Nova;
    
class StudentDetail extends Resource 
{
    public static $model = \App\Models\StudentDetail::class;

    public static $title = 'name';
        
    ...
  1. Change the public 'title()' function if you need to calculate the resource's title.

For example, you want to list the 'App\Model\User' class by last name and then first name. Thus "John Smith" is displayed as "Smith, John":

namespace App\Nova;

...

class User extends Resource
{
    public static $model = \App\Models\User::class;
    
    public function title() {
        return $this->last_name . ', ' . $this->first_name
    }
  • Related