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

Atago's avatar
Level 1

HAS MANY RELATIONSHIP GUIDE USING ELOQUENT ORM

Hello pls am a kind of stuck with Eloquent ORM relationship issue, I have three tables comments, replies and users table respectively. I want to create a relationship for the three tables so that I can get my result in one raw per relationship Below is the tables architecture .

Schema::create('comments', function (Blueprint $table) { $table->increments('id'); $table->string('postedby'); //user_id $table->text('comment'); $table->timestamps(); });

Schema::create('replies', function (Blueprint $table) { $table->increments('id'); $table->string('user_id'); $table->integer('comment_id')->unsigned(); $table->text('reply'); $table->timestamps(); });

Schema::create('users', function (Blueprint $table) { $table->string('id'); $table->string('name'); $table->string('surname'); $table->string('email')->unique(); $table->string('password');

    });

PLS HELP ME WITH THE RELATIONSHIP AND THE CONTROLLER QUERY CODE AS SAMPLE

0 likes
3 replies

Please or to participate in this conversation.