$employee = employee::find(1);
$salary1 = new Salary;
$salary->amount = '123456789';
$salary->payment_date = '15/07/2020';
$salary2 = new Salary;
$salary->amount = '123456789';
$salary->payment_date = '16/07/2020';
$employee = $employee->salary()->saveMany([$salary1, $salary2]);
You should pass an array of user IDs to the attach() method.
For convenience, attach and detach also accept arrays of IDs as input
Change your code to:
$team = AppTeam::findOrFail($request->team_id);
$team->teamMembers()->attach($request->members_id);