From 57202d511227877ea201e7317d1252ed2010af75 Mon Sep 17 00:00:00 2001 From: Emile Lalorcey Date: Mon, 24 Nov 2025 15:15:57 +0100 Subject: [PATCH] =?UTF-8?q?1=20ere=20phase=20compl=C3=A8te?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/ClientController.php | 2 +- app/Http/Controllers/FrontendController.php | 12 +++ public/css/style.css | 72 ++++++++++++++++ resources/views/authentification.blade.php | 0 resources/views/clients.blade.php | 94 ++++++++++++++++++++- resources/views/creationClient.blade.php | 31 ++++--- resources/views/layout.blade.php | 3 - resources/views/majClient.blade.php | 5 ++ routes/api.php | 2 +- routes/web.php | 6 +- 10 files changed, 207 insertions(+), 20 deletions(-) create mode 100644 resources/views/authentification.blade.php create mode 100644 resources/views/majClient.blade.php diff --git a/app/Http/Controllers/ClientController.php b/app/Http/Controllers/ClientController.php index 4e0a8c0..bbfce0e 100644 --- a/app/Http/Controllers/ClientController.php +++ b/app/Http/Controllers/ClientController.php @@ -25,7 +25,7 @@ class ClientController extends Controller } /** - * Requete + * update le client */ public function update(Request $request, $id) { $client = Client::findOrFail($id); diff --git a/app/Http/Controllers/FrontendController.php b/app/Http/Controllers/FrontendController.php index 2b8cca4..8ad0c84 100644 --- a/app/Http/Controllers/FrontendController.php +++ b/app/Http/Controllers/FrontendController.php @@ -27,5 +27,17 @@ class FrontendController extends Controller return view('clients'); } + public function supprimer($id){ + $client = Client::findOrFail($id); + $client->delete(); + return response()->noContent(); + } + public function update(Request $request, $id) { + $client = Client::findOrFail($id); + $client->update($request->all()); + return $client; + } + + public function unClient($id) { return view('majClient'); } } \ No newline at end of file diff --git a/public/css/style.css b/public/css/style.css index ef8aa12..c9f1c60 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -43,3 +43,75 @@ nav { nav a:hover { text-decoration: underline; } + + body { + font-family: "Inter", sans-serif; + background: #f5f6fa; + padding: 50px; + display: flex; + flex-direction: column; + align-items: center; + } + + h1 { + font-weight: 600; + margin-bottom: 35px; + color: #1d1d1f; + } + + .form-clean { + background: #58a198; + padding: 40px 45px; /* plus de padding */ + border-radius: 14px; + width: 100%; + max-width: 450px; + box-shadow: 0 6px 18px rgba(0,0,0,0.06); + display: flex; + flex-direction: column; + gap: 22px; /* spacing entre les champs */ + } + + .field { + display: flex; + flex-direction: column; + gap: 6px; + } + + .form-clean label { + font-size: 15px; + color: #333; + font-weight: 500; + } + + .form-clean input { + padding: 14px 16px; /* plus de padding dans les inputs */ + border-radius: 10px; + border: 1px solid #dcdce0; + background: #fafafa; + font-size: 15px; + transition: 0.25s; + } + + .form-clean input:focus { + border-color: #000; + background: #fff; + box-shadow: 0 0 0 3px rgba(0,0,0,0.07); + outline: none; + } + + .btn-submit { + margin-top: 10px; + padding: 14px 20px; + border-radius: 10px; + border: none; + background: #1d1d1f; + color: #fff; + font-size: 16px; + font-weight: 500; + cursor: pointer; + transition: 0.25s; + } + + .btn-submit:hover { + background: #000; + } \ No newline at end of file diff --git a/resources/views/authentification.blade.php b/resources/views/authentification.blade.php new file mode 100644 index 0000000..e69de29 diff --git a/resources/views/clients.blade.php b/resources/views/clients.blade.php index f50e479..3741f08 100644 --- a/resources/views/clients.blade.php +++ b/resources/views/clients.blade.php @@ -17,6 +17,7 @@ Nom du client Adresse e-mail Voir le client + Supprimer `; @@ -25,16 +26,103 @@ table.innerHTML += ` ${c.nom} ${c.email} - le client ${c.id} + Informations + supprimer `; }); - list.innerHTML += " " + list.innerHTML += " " } catch (error) { console.error('Erreur :', error); list.innerHTML = '
  • Impossible de charger les clients
  • '; } } + + async function supprimer(id){ + try{ + await fetch(`http://192.168.56.56:8000/api/clients/${id}`, { + method: 'DELETE' + }); + await loadClients(); + }catch(err){ + console.error(err); + } + } + + async function leClient(id) { + try { + const response = await fetch(`http://192.168.56.56:8000/api/clients/${id}`, { + method: 'GET' + }); + + if (!response.ok) { + throw new Error("Client introuvable"); + } + + const client = await response.json(); + + // zone d'affichage + const zone = document.getElementById("client-info"); + + // formulaire + zone.innerHTML = ` +

    Modifier le client

    + +
    + +
    +

    + +
    +

    + +
    +

    + +
    +

    + + +
    + `; + } catch (error) { + console.error(error); + document.getElementById("client-info").innerHTML = + "

    Erreur lors du chargement du client.

    "; + } + } + + async function updateClient(id) { + try { + const nom = document.getElementById("edit-nom").value; + const prenom = document.getElementById("edit-prenom").value; + const email = document.getElementById("edit-email").value; + const telephone = document.getElementById("edit-ntelephone").value; + + const response = await fetch(`http://192.168.56.56:8000/api/clients/${id}`, { + method: 'PUT', + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ nom, prenom, email, telephone }) + }); + + if (!response.ok) { + throw new Error("Erreur de mise à jour"); + } + + alert("Client mis à jour !"); + loadClients(); + + } catch (err) { + console.error(err); + alert("Impossible de mettre à jour le client."); + } + } + + loadClients(); + + -@endsection \ No newline at end of file +
    +@endsection + diff --git a/resources/views/creationClient.blade.php b/resources/views/creationClient.blade.php index 23f43a7..7a7ab68 100644 --- a/resources/views/creationClient.blade.php +++ b/resources/views/creationClient.blade.php @@ -2,21 +2,30 @@ @section('content')

    Création d'un nouveau client

    -
    + @csrf - - +
    + + +
    - - +
    + + +
    - - +
    + + +
    - - - - +
    + + +
    + +
    + @endsection \ No newline at end of file diff --git a/resources/views/layout.blade.php b/resources/views/layout.blade.php index 9398862..06a2c59 100644 --- a/resources/views/layout.blade.php +++ b/resources/views/layout.blade.php @@ -10,9 +10,6 @@ Accueil Liste des clients Crée un client - Mise à jour complète d'un client - Mise à jour partielle d'un client - Supprimer un client diff --git a/resources/views/majClient.blade.php b/resources/views/majClient.blade.php new file mode 100644 index 0000000..0cabf68 --- /dev/null +++ b/resources/views/majClient.blade.php @@ -0,0 +1,5 @@ +@extends('layout') +@section('content') + + +@endsection \ No newline at end of file diff --git a/routes/api.php b/routes/api.php index 2259b92..7d9c60a 100644 --- a/routes/api.php +++ b/routes/api.php @@ -13,5 +13,5 @@ Route::get('/user', function (Request $request) { Route::get('/clients', [ClientController::class, 'index']); Route::get('/clients/{id}', [ClientController::class, 'show']) ; Route::delete('/clients/{id}', [ClientController::class, 'destroy']); -Route::post('/clients', [ClientController::class , 'store']); +Route::post('/clients/ajout', [ClientController::class , 'store']); Route::put('/clients/{id}', [ClientController::class, 'update']); \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 58c5b98..1163d72 100644 --- a/routes/web.php +++ b/routes/web.php @@ -9,4 +9,8 @@ Route::get('/', function () { Route::get('/', [FrontendController::class, 'accueil']); Route::get('/clients', [FrontendController::class, 'clients']); -Route::get('/ajoutClient', [FrontendController::class, 'creer']); \ No newline at end of file +Route::get('/ajoutClient', [FrontendController::class, 'creer']); +Route::post('/clients/ajout', [FrontendController::class, 'ajout']); +Route::delete('/clientsDel/{id}', [FrontendController::class, 'supprimer']); + +Route::put('/majClient/{id}',[FrontendController::class, 'update']);