Skip to content

Commit

Permalink
fix update user controls
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarzin committed Jun 26, 2023
1 parent fa07b46 commit 9607d5a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ public function update(Request $request, User $user)
$user->password = bcrypt(request('password1'));
}

// TODO : should not update controls already made
$user->controls()->sync($request->input('controls', []));
// Update controls not already made
$user->lastControls()->sync($request->input('controls', []));

$user->update();

Expand Down
5 changes: 5 additions & 0 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ public function controls()
{
return $this->belongsToMany(Control::class)->orderBy('clause');
}

public function lastControls()
{
return $this->belongsToMany(Control::class)->whereNull('realisation_date')->orderBy('clause');
}
}
2 changes: 1 addition & 1 deletion resources/views/users/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
</tr>
</thead>
<tbody>
@foreach($user->controls as $control)
@foreach($user->lastControls as $control)
<tr>
<td>
<a id="{{ $control->domain->title }}" href="/domains/{{ $control->domain_id}}">
Expand Down

0 comments on commit 9607d5a

Please sign in to comment.