My checkbox
are saving normally, however, when I leave the page and return, they are not checked.
Clients.blade.php
<body><formmethod="POST" action="/user/update/client">
<input type="hidden" name="id" value="{{$user->ID}}" />
<h1>BEM VINDO ADMINISTRADOR!</h1>
<div><input type="button" value="Início" id="inicio" name="Início" onclick="window.location.href='/inicioadm';"></div> <br>
@foreach ($clients as $client)
<table style="width:100%">
<tr>
<th width="30%"><p>Nome: {{$client->Nome}} <input name="clientes[]" type="checkbox" value="{{$client->ID}}"> </p></th>
</tr>
</table>
@endforeach
<br><div><input type="submit" value="Salvar" id="salvar" name="Salvar" onclick="window.location.href='/desenvolvedores"/div>
</form>
</body>
Controller
public function updateClient()
{
$clientList = Input::get("clientes");
$user = Input::get("id");
\App\Relation::where('ID_user', $user)->delete();
if($clientList)
{
foreach($clientList as $c)
{
$r = new \App\Relation();
$r->ID_clients = $c;
$r->ID_user = $user;
$r->save();
}
}
return redirect("/desenvolvedores");
}
Model Clients
class Clients extends Model
{
public function Users ()
{
return $this->belongsToMany("\App\Relation", "relations", "ID_clients", "ID"); //conectando as tabelas 'users' e 'clients' do banco de dados
}
}