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

thenaim's avatar

Laravel Nova HasOne Related Models Fields Create/Update Issue

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: Imgur

Create Result: Imgur

Update: Imgur

Update Result: Imgur

0 likes
2 replies

Please or to participate in this conversation.