<?php
use App\Models\Permission;
use App\Models\Role;
?>


<h2>Utenti con il ruolo {{ $role->name }}</h2>



<ul style="list-style-type:none">
  @foreach($role->users as $user)
  <li>
    <i class="far fa-trash-alt" onclick="rimuovi_utente({{ $user->id }})"></i> {{ $user->full_name }}
  </li>
  @endforeach
</ul>

<script>
$(document).ready(function(){
  $.ajaxSetup({
    headers: {
      'X-CSRF-TOKEN': '{{csrf_token()}}'
    }
  });
});

function rimuovi_utente(user_id){
  $.ajax({
    type: "POST",
    async: false,
    url: "{{ route('roles.rimuovi_utente') }}",
    data: {
      user_id: user_id,
      role_id: "{{ $role->id }}",
      _token : "{{csrf_token()}}",
    },
    success: function(data){
      load_utenti("{{ $role->id }}");
    },
    error: function(XMLHttpRequest, textStatus, exception) { alert("Ajax failure\n" + XMLHttpRequest.responseText + "\n" + exception); },
  });
}
</script>
