As you are using a pivot table, you have a many-to-many relationship, so the relations in your models should be using the belongsToManymethod in both models.
class Magazine_category extends Model
{
protected $fillable = [ 'name' ];
public function subcategories()
{
return $this->belongsToMany('App\Magazine_subcategory', 'magazine_category_subcategory', 'category_id', 'subcategory_id' );
}
}
And
class Magazine_subcategory extends Model
{
protected $fillable = [ 'name' ];
public function categories()
{
return $this->belongsToMany('App\Magazine_category', 'magazine_category_subcategory', 'subcategory_id', 'category_id');
}
}
Then change your view to use the relationship method:
<ul>
@foreach($categories as $category)
<li>{{ $category->name }}
<ul>
@foreach($category->subcategories as $subcategory)
<li>{{ $subcategory->name }}</li>
@endforeach
</ul>
</li>
@endforeach
</ul>
Read more about using many-to-many relationships is the docs: https://laravel.com/docs/5.6/eloquent-relationships#many-to-many