3

Is it possible to group several column names and use them as the label / title in a select BelongsTo, I don't want to use ID and don't have a 'name' field as such as the table in question is like this:

  • Country
  • State
  • Cost

So the dropdown should be able to allow the user to see those names like:


USA | Washington | $50.00

USA | California | $80.00

USA | Texas | $30.00


user1983183
  • 88
  • 1
  • 6

1 Answers1

17

Documentation says, that you may override the resource's title method:

/**
 * Get the value that should be displayed to represent the resource.
 *
 * @return string
 */
public function title()
{
    return $this->name;
}

For some form specific display you can use:

BelongsTo::make('SomeModel', 'somemodel', 'App\Nova\SomeModel')
         ->display(function($someModel){ 
             return $someModel->id.' wow so custom, much id'; 
         }),
Sanasol
  • 892
  • 8
  • 24
  • I only want to override the title in the field on the form screen. The doc you cited is for the resource itself from what I gathered – user1983183 Mar 07 '19 at 15:40
  • Awesome - thanks a lot! Do you know if in the index view it's possible to then make this 'display' as a 'show more' expand – user1983183 Mar 07 '19 at 16:08
  • @user1983183 index display can be changed with ->displayUsing(), but not sure that html/link allowed inside. – Sanasol Mar 07 '19 at 16:14
  • No worries - I'll build a second field for index view and one for forms only. Thanks again – user1983183 Mar 07 '19 at 16:20