If you need to send variable to wherehas function , all you have to do it to use “use” .. here is an example…
To list the Users whom their posts are in certain langue .
$language = 3; $users = Users::whereHas('posts', function ($query) use($language){ $query->where('language_id', $language); })->get();