1 year ago

Get the user who belongs to a thread.

Posted 1 year ago by nanadjei2

I have a threads table where either a user or admin can post a new thread.That means I have a "users table" and "admin table" . I want to retrieve the user's name of each thread. Can anyone help me out please.

This is my migrations;

  public function up()
          Schema::create('threads', function (Blueprint $table) {
              $table->engine = 'InnoDB';
              // $table->unsignedInteger('user_id')->reference('id')->on('users')->onDelete('restrict');
             $table->string('user_type', 50)->nullable();

             $table->enum('resolved_status', ['Resolved', 'Awaiting...'])->default('Awaiting...');
             $table->enum('status', ['Draft', 'Published'])->default('Draft');

This is my relationship in Threads.php

              public function user()
                 return $this->morphMany(User::class, 'users', 'user_type', 'user_id');

This is the link to my db image

Please sign in or create an account to participate in this conversation.