I have three tables in my database:
- inquiry
- post
- product
Columns in inquiry
table:
- id
- message
- post
Columns in post
table:
- id
- title
- content
- product
Columns in product
table:
- id
- 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?