Laravel 2是否每个都一样?

时间:2018-07-26 11:25:27

标签: php mysql laravel

我是laravel的新手,我试图了解如何使其变得更好。现在,我已经看到了代码:

<table class="table table-hover"  data-model-table="1" data-brighten-first="1">
    <thead><tr>
    <th>Date</th>
        <th>Reason</th>
        <th>Banned by</th>
                <th>Time</th>
    </tr></thead>
    @foreach ($user->BanHistory as $BanHistory)
    <tr>
        <td>{{ $BanHistory->date }}</td>
        <td>{{ $BanHistory->reason }}</td>
        <td>
       @foreach ($user->AdminBanHistory as $BanAdmin)
        {{ $BanAdmin->username }}
        @endforeach
            </td>
        <td>{{ round($BanHistory->banlength / 1440) }} days.</td>
    </tr>
    @endforeach

但是随着2 foreach我变得一团糟。任何建议,我怎么能使它吸气?因为我现在得到

{{ $BanAdmin->username }}

@foreach ($user->BanHistory as $BanHistory)相同。对不起,如果您不明白我的问题和我需要什么。

PS:我的控制器:

$user->BanHistory = DB::table('server_bans_history AS sh')
->leftJoin('users AS us', 'us.steam_id', '=', 'sh.steamid', 'us.steam_id', '=', 'sh.admin_steamid')
->where('sh.steamid', '=', $user->steam_id)
->select("sh.*", "us.username")
->orderBy('sh.date', 'desc')
->get('');

$user->AdminBanHistory = DB::table('server_bans_history AS sh')
->leftJoin('users AS us', 'us.steam_id', '=', 'sh.admin_steamid')
->select("us.username")
->get('');

谢谢你们对我的帮助!

0 个答案:

没有答案