3

I'm using Laravel and Nova, I have a Collection resource which has multiple fields, now when you define the fields for example:

Text::make('Meta 1 Label')->hideFromIndex(),
Text::make('Meta 1 Value')->hideFromIndex(),
Text::make('Meta 2 Label')->hideFromIndex(),
Text::make('Meta 2 Value')->hideFromIndex(),
Text::make('Meta 3 Label')->hideFromIndex(),
Text::make('Meta 3 Value')->hideFromIndex(),
Text::make('Meta 4 Label')->hideFromIndex(),
Text::make('Meta 4 Value')->hideFromIndex(),

Each field will take up one row, in the html.

with

Now I'm wondering if it's possible to have custom layout options (without having to make a full blown custom Tool), so that it's possible for example to group a few text fields in a div. and have the label and value field on one line

Pseudo Code

<div class="flex">
    Text::make('Meta 1 Label')->hideFromIndex(),
    Text::make('Meta 1 Value')->hideFromIndex(),
</div>
<div class="flex">
    Text::make('Meta 2 Label')->hideFromIndex(),
    Text::make('Meta 2 Value')->hideFromIndex(),
</div>
Miguel Stevens
  • 8,631
  • 18
  • 66
  • 125

1 Answers1

0

You can try this instead

public function fields(Request $request)
{
    return [
        ID::make()->sortable(),

        new Panel('Group 1', $this->group1()),
        new Panel('Group 2', $this->group2()),
    ];
}

protected function group1()
{
    return [
        Text::make('Meta 1 Label')->hideFromIndex(),
        Text::make('Meta 1 Value')->hideFromIndex(),
    ];
}

protected function group2()
{
    return [
        Text::make('Meta 2 Label')->hideFromIndex(),
        Text::make('Meta 2 Value')->hideFromIndex(),
    ];
}

Check field-panels laravel nova doc section for more information.

Ankit.Z
  • 740
  • 8
  • 20