Laravel.io
// routes/web.php
Route::get('categoryid/{category}/parentcategory/{parent?}', 'ForumController@show');


// app/Http/ForumController.php
public function show(ForumCategory $category, ForumParentCategory $parent)
{
    if ($parent->exists) {
        // If you have relations setup, you could just use $category->threads to access it's related/attached threads
        $threads = DB::table('threads')->whereIn('category_id', function ($query) use ($category) {
            $query->select('id')
                ->from('categories')
                ->where('parent_category_id', $category->id);
        })->get();

        return view('thread.subcategories.subcat', ['threads' => $threads]);
    }

    $threads = DB::table('threads')->where('category_id', $category->id)->get();
    // If you have relations setup, you could just use $category->threads to access it's related/attached threads

    dd($catThreads);
}

Please note that all pasted data is publicly available.