WordPress has two tables named posts
and woocommerce_sessions
, and I want to connect these two tables in Laravel
using the models I created. The issue is that the woocommerce_sessions
table does not have an ID; it uses session_id
.
woocommerce_sessions
structure:
session_id -> Primary
session_key -> Index
session_value
session_expiry
posts
structure:
ID -> PrimaryIndex
post_author -> Index
post_date
post_date_gmt
post_content
post_title
...
The relationships I created are as follows:
WoocommerceSessions:
public function product(): BelongsTo
{
return $this->belongsTo(Post::class, 'session_id', 'ID');
}
Posts:
public function session(): BelongsTo
{
return $this->belongsTo(WoocommerceSessions::class, 'session_id', 'ID');
}
and getting query:
$product = $this->product()->find($c['product_id']); // return null
The output of this relationship is null, which is incorrect.