I'm trying to take out admin username by leftJoin. I have a table called server_bans_history and users.
server_bans_history table have a unique row called steamid and admin_steamid
taking all data by:
@foreach ($user->BanHistory as $BanHistory)
This code works fine, but i dont know hot got admin_steamid row and i need convert that steamid to username from users table.
Becouse now if i use {{ $BanHistory->username }}
i'm getting BANNED user USERNAME not ADMIN username.
Example now i'm using code:
$user->BanHistory = DB::table('server_bans_history AS sh')
->leftJoin('users AS us', 'us.steam_id', '=', 'sh.steamid')
->where('sh.steamid', '=', $user->steam_id)
->select("sh.*", "us.*")
->orderBy('sh.date', 'desc')
->get('');
I need to convert admin_steamid -> user.username
Can i do with multiple leftJoin or something like that?
Thanks for helping me uderstand leftJoin!
I think this should be it:
$user->BanHistory = DB::table('server_bans_history AS sh')
->leftJoin('users AS us', 'us.steam_id', '=', 'sh.steamid')
->leftJoin('users AS us2', 'us.steam_id', '=', 'sh.admin_steamid')
->where('sh.steamid', '=', $user->steam_id)
->select("sh.*", "us.*", "us2.username as admin_name")
->orderBy('sh.date', 'desc')
->get('');