Я не могу найти способ заполнить флажки данными из базы данных.У меня есть таблица ролей (идентификатор и имя роли), таблица пользователей (идентификатор, имя, фамилия и т. Д.) И сводная таблица (user_id, role_id).Как мне заполнить их, чтобы отображалось, если пользователь является администратором / пользователем или обоими?
Спасибо.
controller
{
$total_row = $data->count();
$output = "";
if ($total_row > 0) {
foreach ($data as $row) {
$roleNames = '';
foreach (Role::all() as $roles1) {
$roleNames .= $roles1->role != null ? $roles1->role.' '.'<input type="checkbox" class="checkbox" id="checkboxId">'.' ' : '';
// if ($roles1 = id(1)) {
// return '<input type="checkbox" class="checkbox" id="checkboxId" checked>';
// }
}
$output .= '
<tr>
<td>'.$row->surname.'</td>
<td>'.$row->name.'</td>
<td>'.$row->phone.'</td>
<td>'.$roleNames.'</td>
<td><button type="button" id="rowId" class="remove-button btn btn-danger" data-id="'.$row->id.'">
<div class="close">x</div>
</button></td>
</tr>
';
}
} else {
$output = '
<tr>
<td align="center" colspan="5">Nema podataka</td>
</tr>
';
}
return array(
'table_data' => $output,
'total_data' => $total_row,
);
}