accessing inverse hasmany in controller laravel

Solution 1:

First and foremost i'd define the foreignIDS in the relations just to make sure that are working as expected.

class Topic extends Model
{
    public function categories()
    {
        return $this->hasMany(HowtoCategory::class);
    }

    public function sections()
    {
        return $this->hasManyThrough(
            Howto::class, HowtoCategory::class,
           "topic_id", "howto_category_id"
        );
    }
}

then you can get the Topics by searching the sections like so

use Illuminate\Database\Eloquent\Builder;

$topics = Topic::whereHas("sections", function(Builder $query) {
    $query->where("howto.description", "something to search")
})->get();