0

I'm trying to take out STEAM_ID to nickname.

Example: I have table row called player_id, and another table users with row called username. I'm trying to convert STEAM_ID to username. Example: STEAM_0:0:1236546695 to username: ADMIN.

Code:

public function index()
{
    $this->title('Banned players');
    $this->indexPage([
        'buttons'       => null,
        'brightenFirst' => false,
        'sortby' => 'bid',
        'tableHead'     => [
        'ID' => 'id',
            'Player'           => 'player_id',
            'Length' => 'length',
            'Reason' => 'reason',
            'Banned by' => 'admin',
        ],
        'tableRow'      => function($bans_bans)
        {
            return [
            $bans_bans->bid,
                $bans->banusername,
                $bans_bans->ban_length,
                $bans_bans->ban_reason,
                $bans_bans->admin_id,
            ];
                $bans->banusername = User::where('steam_id', '=', $bans_bans->player_id)->first()->username;
        },
        'actions'       => null,
    ], 'front');
}

But getting error:

Undefined variable: bans

Any help? I'm new on laravel so dont be mad on me! Thanks for answers guys!

Nigel Ren
  • 56,122
  • 11
  • 43
  • 55

1 Answers1

2

You are using $bans instead of $bans_bans by mistake. There are 2 places you need to change it. Try this code:

return [
    $bans_bans->bid,
    $bans_bans->banusername,
    $bans_bans->ban_length,
    $bans_bans->ban_reason,
    $bans_bans->admin_id,
];
$bans_bans->banusername = User::where('steam_id', '=', $bans_bans->player_id)->first()->username;
Lovepreet Singh
  • 4,792
  • 1
  • 18
  • 36