Your table structure should be like this with foreign keys
categories
id - integer
name - string
description - text
versions
id - integer
category_id - integer
name - string
posts
id
user_id - integer
category_id - integer
version_id - integer
title - string
slug - string
body - text
And you need belongsTo and hasMany relationships
Just follow documentation https://laravel.com/docs/8.x/eloquent-relationships#defining-relationships
For example
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Category extends Model
{
/**
* Get the comments for the blog post.
*/
public function posts()
{
return $this->hasMany('App\Models\Post');
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
/**
* Get the post that owns the comment.
*/
public function post()
{
return $this->belongsTo('App\Models\Category');
}
}