如何在laravel中编写查询以从多个表中获取结果

I am doing project in laravel. There are two tables "categories" and "subcategories". "subcategories" table have categoryid as a foreign key. I want to fetch categoryname from categories table and subcategoryid,subcategoryname from subcategories table where categoryid = $categoryid.

Here is something what I did. $cat contains many categoryid's but, from this I got only subcategories details,

foreach($cat as $categoryid){
        $subcategories[] = Subcategory::where('categoryid', '=', $categoryid)->get();
}

I am not getting how to do this,please help.