Hello Everone,
Nova HasOne related models fields, create/update no effect. Can anyone here help me, please? Thanks.
Product Table:
Schema::create('products', function (Blueprint $table) {
$table->id();
$table->string('name')->unique()->index();
$table->timestamps();
});
Product Details Table:
Schema::create('product_details', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('product_id');
$table->longText('description');
$table->double('price');
$table->timestamps();
$table->foreign('product_id')->references('id')
->on('products')
->onDelete('cascade');
});
Product Eloquent Model Relationship:
public function detail()
{
return $this->hasOne('App\ProductDetail');
}
ProductDetail Eloquent Model Relationship:
public function product()
{
return $this->belongsTo('App\Product', 'product_id');
}
Product Nova Resource:
public function fields(Request $request)
{
return [
ID::make()->sortable(),
Text::make('name')->sortable(),
Text::make('Description', 'detail.description'),
Number::make('Price', 'detail.price'),
];
}
Create New:

Create Result:

Update:

Update Result:
