40 lines
1.8 KiB
PHP
40 lines
1.8 KiB
PHP
@extends('layout')
|
|
@section('content')
|
|
<link href="{{ asset('css/style.css') }}" rel="stylesheet">
|
|
<h1>Liste des clients</h1>
|
|
<ul id="clients-list"></ul>
|
|
{{-- Définition et exécution d'une fonction javascript pour afficher les clients --}}
|
|
<script>
|
|
async function loadClients() {
|
|
try {
|
|
//appel de l'api
|
|
const response = await fetch('http://192.168.56.56:8000/api/clients');
|
|
const clients = await response.json();
|
|
const list = document.getElementById('clients-list');
|
|
list.innerHTML = `<table>
|
|
<thead>
|
|
<tr>
|
|
<th scope=\"col\">Nom du client</th>
|
|
<th scope=\"col\">Adresse e-mail</th>
|
|
<th scope=\"col\">Voir le client</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody> `;
|
|
const table = list.querySelector("table")
|
|
clients.forEach(c => {
|
|
table.innerHTML += `<tr>
|
|
<td>${c.nom}</td>
|
|
<td>${c.email}</td>
|
|
<td><a href="{{ url('/clients/${c.id}') }}">le client ${c.id}<a></td>
|
|
</tr>`;
|
|
});
|
|
list.innerHTML += "</tbody> </table>"
|
|
|
|
} catch (error) {
|
|
console.error('Erreur :', error);
|
|
list.innerHTML = '<li>Impossible de charger les clients</li>';
|
|
}
|
|
}
|
|
loadClients();
|
|
</script>
|
|
@endsection |