1

I have three tables in my database:

  1. inquiry
  2. post
  3. product

Columns in inquiry table:

  1. id
  2. message
  3. post

Columns in post table:

  1. id
  2. title
  3. content
  4. product

Columns in product table:

  1. id
  2. name

I have an Inquiry model and I want to show the post title and product name with my inquiry.

I found that hasOneThrough can help me with this and so far I have tried this:

Inquiry Model

class Inquiry extends Model {
   use HasFactory;

   public function product() {
      return $this->hasOneThrough(Product::class, Post::class, 'product', 'id', 'post', 'product');
   }
}

Post Model

class Post extends Model {
   use HasFactory;

   public function product() {
      return $this->hasOne(Product::class, 'id', 'product');
   }
}

Product Model

class Product extends Model {
   use HasFactory;
}

I followed this page from laravel documentation.

So far, this code is giving me internal server error. Can someone explain what is wrong with this code and how can I fix it?

Dev2
  • 11
  • 1
  • Hi ! when you have internal server error, Laravel gives you tons of useful information in the log file. You can usually find it in `storage/logs/laravel.log` Can you edit your question to include the error log you get for this error ? – YannPl Nov 17 '21 at 10:19

0 Answers0