Emon Jug
Jul 17, 2023
4
Level 1
BelongsTOManyField nova 4
Hello,
I have a relationship made between 2 tables products and orders and a pivot table.
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function products(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(Product::class, 'orders_products', 'order_id', 'product_id');
}
Schema::create('orders_products', function (Blueprint $table) {
$table->bigIncrements('id');
$table->bigInteger('order_id')->unsigned();
$table->bigInteger('product_id')->unsigned();
$table->foreign('order_id')->references('id')->on('orders')
->onDelete('cascade');
$table->foreign('product_id')->references('id')->on('products')
->onDelete('cascade');
});
Now my question is: How can I add a select in nova 4 for many to many? I tried this field
return [
ID::make()->sortable(),
Text::make('Total comanda', 'total'),
Text::make('Locatie', 'location'),
Text::make('Mesaj de la client', 'message_from_client'),
HasOne::make('Utilizator', 'user_id', User::class),
BelongsToManyField::make('Produse', 'products', Product::class)
->optionsLabel('name')
->options(Product::all())
//->rules('required', 'min:1'),
];
The problem is that it no longer works in nova 4 and I get an error. Any other ideas?
Please or to participate in this conversation.