I have this big function that is calling a lot of other functions who that make API requests to BlackBoard, my problem is, in this main function, I create my user and sign him to the current course, but actually we faced this situation: that same user is already registered in BlackBoard, so I made an update function, to that specific case. But that main function it's all in a try catch block, so every time that I call the method:
$userSalvo = $bd->createUser($user)
and the user already exist in BlackBoard database, he immediatly stop my function and call the catch block, to obviously get the exception, but I need if that user already exist, he comeback from this request and go to the next method:
$userSalvo = $bd->updateUser($user, $userId);
I already tried to put this in a if statement, but It doesnt work as it should:
if($userSalvo = $bd->createUser($user))
{
dd('create');
$user->id = $userSalvo['id'];
}else
{
dd('update');
$userSalvo = $bd->updateUser($user, $userId);
$user->id = $userSalvo['id'];
}
Anyone has some ideia of how can I do this?
This is the API method that I'm calling to update/create:
public function updateUser($user, $userId)
{
$user->dataSourceId = $this->dataSourceId;
return $this->bd->patch("/users/{$userId}", json_decode(json_encode($user), true));
}
public function createUser($user)
{
$user->dataSourceId = $this->dataSourceId;
return $this->bd->post("/users", json_decode(json_encode($user), true));
}