$user = User::with(['posts'])->first();
$user_id = $user->id;

ってコントローラーでしたら駄目なんですか?
vscodeさんがUndefined propertyってエラー出してくるんですが