CRUGG
1 month ago

Modify User in Controller - Integrity constraint violation: 4025

Posted 1 month ago by CRUGG

Hey there. I am currently working on making it possible for my Users to link their Social Media Accounts to their Accounts on my Website using Socialite. When being redirected to my callback, I get this error:

SQLSTATE[23000]: Integrity constraint violation: 4025 CONSTRAINT `users.connection_discord` failed for `***_hub`.`users` (SQL: update `users` set `connection_steam` = {"name":"CRUGG","id":76561198308261486,"url":"https:\/\/steamcommunity.com\/id\/crugg_\/"}, `users`.`updated_at` = 2020-08-08 16:54:56 where `id` = 1)

The Function I use to handle the Callback and to modify the User to add the Information looks like this:

/**
 * Handles the callback of the authentification provider.
 *
 * @return \Illuminate\Http\Response
 */
public function callback($service)
{
    $account = Socialite::driver($service)->user();
    $data = ['name' => $account->nickname, 'id' => $account->id];
    $user = User::find(Auth::user()->id);
    switch($service) {
        case "github":
            $data['url'] = $account->user['html_url'];
            $user->connection_github = json_encode($data);
            break;
        case "discord":
            $data['url'] = 'https://discord.com/users/' . $account->id;
            $user->connection_discord = json_encode($data);
            break;
        case "steam":
            $data['url'] = $account->user['profileurl'];
            $user->connection_steam = json_encode($data);
            break;
        default:
            return 'error';
    }
    $user->save();
    return view('connections.' . $service);
}

Please sign in or create an account to participate in this conversation.