Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

theProfit's avatar

Attaching + extra pivot info

Hi all,

I have 3 models

  • Company
  • Partner
  • Application

now i have pivot table

application_company here i have :

  • Application_id
  • Company_id
  • Partner_id

when i want in nova to attach a partner on a company i want also to fill the partner_id ?

in the models i have withPivot('partner_id')

0 likes
3 replies
manojo123's avatar

You can give the user the option to define the partner_id By adding this method in your field array

//Nova/Company.php
BelongsToMany::make('Application')
    ->fields(function () {
        return [
            BelongsTo::make('Partner')
        ];
    }),
theProfit's avatar

@manojo123 Thanks but it dont work, i dont know if it is posible in nova to have 2 dropdowns for 2 relations? it would be nice if this works.

theProfit's avatar
        return [
            Text::make(__('Name'), 'name')->sortable(),
            BelongsToMany::make('Applications')
                ->fields(function () {
                    return [
                        ID::make('partner_id'),
//                      Select::make('partner_id')->options([
//                            'A' => 1,
//                            'B' => 2,
//                            'C' => 3,
//                        ])
                    ];
                }),
            BelongsToMany::make('partners')
        ];

This works only i need to fill in the id by had, witch is nice for to test but my goal, so i tried with a select field, but when i select option A it will insert A into the database and not 1, witch result in a error. So i am looking now to make a nice dropdown.

Please or to participate in this conversation.