Below code works adding single single entry i want to store multiple parent_id and user_id
public function test($p_id, $pl_id)
{
$CheckRelationship = UsersRelationship::where('parent_user_id', $p_id )->where('child_user_id', $pl_id )->first();
if( $CheckRelationship )
{
return Response::json( [
'ok'=> false,
'message'=> 'The profiles are currently linked '
] ,422);
}
$user = User::find( $pl_id );
$user->p_id = $p_id;
$user->updated_by = $p_id;
//$user->status = 1;
$user->save();
$UsersRelationship = new UsersRelationship;
$UsersRelationship->parent_user_id = $parent_id;
$UsersRelationship->child_user_id = $player_id;
$UsersRelationship->save();
return Response::json( [
'ok'=> true,
'message'=> 'Linked',
] ,200);
}
I want to pass multiple value
$UsersRelationship = new UsersRelationship;
$UsersRelationship->parent_user_id = $parent_id; //single value passing
$UsersRelationship->child_user_id = $player_id; //single value passing
$UsersRelationship->save();
foreach($UsersRelationship as $k=>$values){
$UsersRelationship['parent_user_id'] = $values;
$UsersRelationship['child_user_id'] = $values;
$UsersRelationship->save();
}
doesn't work for me please suggest where i am mistaking early reply highly appreciated thanks in advance
->save()inside foreach