/
home
/
obinna
/
html
/
cravings
/
resources
/
views
/
admin
/
Upload File
HOME
@extends('layouts.admin') @section('style') @parent <style> .change-role { display: flex; } .table { table-layout: fixed; } </style> @endsection @section('content') <div class="row"> <div class="col-md-12"> <div class="card"> <div class="card-header"> <h4 class="card-title">Users</h4> </div> <div class="card-body"> <div class="table-responsive"> <table class="table"> <thead class="text-primary"> <tr> <th>Name</th> <th>Email</th> <th>Role</th> <th>Actions</th> </tr> </thead> <tbody> @foreach($users as $user) <tr> <td>{{ $user->name }}</td> <td>{{ $user->email }}</td> <td data-email="{{ $user->email }}" class="change-role"> <select name="role" class="form-control"> <option {{ $user->role === 'user' ? 'selected' : '' }} value="user">User</option> <option {{ $user->role === 'tester' ? 'selected' : '' }} value="tester">Tester</option> <option {{ $user->role === 'admin' && !$user->super ? 'selected' : '' }} value="admin">Admin</option> <option {{ $user->super ? 'selected' : '' }} value="super">Super Admin</option> </select> <button type="button" class="btn btn-primary handle-change">Change</button> </td> <td> <a href="{{ route('user_places', ['id' => $user->id])}}">Additions</a> | <a href="{{ route('delete_user', ['id' => $user->id])}}">Delete</a> @if($user->started) | <a href="{{ route('user_answers', ['email' => $user->email])}}">Answers</a> @endif </td> </tr> @endforeach </tbody> </table> </div> </div> </div> </div> </div> @endsection @section('scripts') <script> document.querySelectorAll('.handle-change').forEach(button => { button.addEventListener('click', function(e) { const row = e.target.closest('.change-role'); const user = row.dataset.email; const select = row.querySelector('select'); const option = select.value; console.log(row, user, option) const headers = { 'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').getAttribute('value'), 'X-Requested-With': 'XMLHttpRequest' } fetch('/admin/user/role', {method: 'POST', credentials: 'same-origin', body: JSON.stringify({user, option}), headers}) .then(response => response.json()) .then(result => { if(result.status === 'OK') { select.value === result.role alert('role changed') } }) }) }); </script> @endsection